Created
January 9, 2019 06:37
-
-
Save ezirmusitua/a68f9a523870f6966dc8347d20312475 to your computer and use it in GitHub Desktop.
[Nginx static site config] use nginx to serve static site(use letsencrypt cert & mantain with certbot) #deploy #nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## sitename.com | |
server { | |
listen 80; | |
listen [::]:80; | |
# expires $expires; | |
server_name <site_name>; | |
location ^~ /.well-known/acme-challenge/ { | |
default_type "text/plain"; | |
root /opt/sites/cert-webroot/; | |
} | |
location = /.well-known/acme-challenge/ { | |
return 404; | |
} | |
return 301 https://$server_name$request_uri; | |
} | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
server_name ezirmusitua.site; | |
root /opt/sites/blog; | |
index index.html index.htm index.nginx-debian.html; | |
ssl_certificate /etc/letsencrypt/live/<site_name>/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/<site_name>/privkey.pem; | |
keepalive_timeout 120; | |
server_tokens off; | |
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains"; | |
location / { | |
# First attempt to serve request as file, then | |
# as directory, then fall back to displaying a 404. | |
try_files $uri $uri/ =404; | |
} | |
error_page 404 /404.html; | |
} | |
## www.sitename.com | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name www.<site_name>; | |
return 301 https://<site_name>$request_uri; | |
} | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
server_name www.<site_name>; | |
ssl_certificate /etc/letsencrypt/live/<site_name>/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/<site_name>/privkey.pem; | |
return 301 https://<site_name>$request_uri; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment