Last active
September 19, 2016 11:19
-
-
Save AndreiD/3d4b36c58fa59c8ec1ef98276eacb636 to your computer and use it in GitHub Desktop.
secure_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
# always redirect to https ? | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
server_name example.com www.example.com; | |
return 301 https://$server_name$request_uri; | |
} | |
===================== | |
server { | |
listen 80; | |
listen [::]:80; | |
root /home/path; | |
# Add index.php to the list if you are using PHP | |
index index.html index.htm index.nginx-debian.html; | |
server_name yourdomain.com www.yourdomain.com; | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; | |
ssl_ecdh_curve secp384r1; | |
ssl_session_cache shared:SSL:10m; | |
ssl_session_tickets off; | |
ssl_stapling on; | |
ssl_stapling_verify on; | |
resolver 8.8.8.8 8.8.4.4 valid=300s; | |
resolver_timeout 5s; | |
# Disable preloading HSTS for now. You can use the commented out header line that includes | |
# the “preload” directive if you understand the implications. | |
#add_header Strict-Transport-Security “max-age=63072000; includeSubdomains; preload”; | |
add_header Strict-Transport-Security “max-age=63072000; includeSubdomains”; | |
add_header X-Frame-Options DENY; | |
add_header X-Content-Type-Options nosniff; | |
ssl_dhparam /etc/ssl/certs/dhparam.pem; | |
location /static/ { | |
expires 30d; | |
add_header Last-Modified $sent_http_Expires; | |
alias /home/path/application/static/; | |
} | |
location / { | |
try_files $uri @tornado; | |
} | |
location @tornado { | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_pass http://127.0.0.1:1337; | |
} | |
} | |
and this is a config for a subdomain if you have any | |
server { | |
listen 80; | |
listen [::]:80; | |
root /home/path/subdomain; | |
# Add index.php to the list if you are using PHP | |
index index.html index.htm index.nginx-debian.html; | |
server_name subdomain.your_domain.com; | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; | |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
ssl_ciphers “EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH”; | |
ssl_ecdh_curve secp384r1; | |
ssl_session_cache shared:SSL:10m; | |
ssl_session_tickets off; | |
ssl_stapling on; | |
ssl_stapling_verify on; | |
resolver 8.8.8.8 8.8.4.4 valid=300s; | |
resolver_timeout 5s; | |
# Disable preloading HSTS for now. You can use the commented out header line that includes | |
# the “preload” directive if you understand the implications. | |
#add_header Strict-Transport-Security “max-age=63072000; includeSubdomains; preload”; | |
add_header Strict-Transport-Security “max-age=63072000; includeSubdomains”; | |
add_header X-Frame-Options DENY; | |
add_header X-Content-Type-Options nosniff; | |
ssl_dhparam /etc/ssl/certs/dhparam.pem; | |
location /static/ { | |
expires 30d; | |
add_header Last-Modified $sent_http_Expires;alias /home/path/subdomain/static/; | |
} | |
location / { | |
try_files $uri @tornado2; | |
} | |
location @tornado2 { | |
proxy_pass http://localhost:1338; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection “upgrade”; | |
proxy_set_header Host $host; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment