Skip to content

Instantly share code, notes, and snippets.

@terrychan999
Created January 30, 2021 12:17
Show Gist options
  • Save terrychan999/9af84e7f1dc578d7d94c441818238dcf to your computer and use it in GitHub Desktop.
Save terrychan999/9af84e7f1dc578d7d94c441818238dcf to your computer and use it in GitHub Desktop.
Nginx Certbot PHP-fpm example
server {
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php;
server_name example.com; # managed by Certbot
autoindex off;
error_log /var/log/nginx/example_error.log;
access_log /var/log/nginx/example_access.log;
client_max_body_size 0;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/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
}
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80 ;
listen [::]:80 ;
server_name example.com;
return 404; # managed by Certbot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment