Skip to content

Instantly share code, notes, and snippets.

@mahaverick
Created January 4, 2019 07:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahaverick/df3e1e829f9f89863da46e650e8c522a to your computer and use it in GitHub Desktop.
Save mahaverick/df3e1e829f9f89863da46e650e8c522a to your computer and use it in GitHub Desktop.
nginx config for laravel app with lets encrypt ssl and transfer all requests from non-www to www
#this is my config
server {
listen [::]:443 ssl ipv6only=on default_server; # managed by Certbot
listen 443 ssl default_server; # managed by Certbot
server_name www.zilpi.in;
root /var/www/zilpi/public;
ssl_certificate /etc/letsencrypt/live/zilpi.in/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/zilpi.in/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
# With php7.2-fpm:
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
#fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
#fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
server {
listen 80;
listen [::]:80;
if ($host = www.zilpi.in) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = zilpi.in) {
return 301 https://www.$host$request_uri;
} # managed by Certbot
server_name zilpi.in www.zilpi.in;
return 404; # managed by Certbot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment