|
| 1 | +## http://subdomain.example.org redirects to https://subdomain.example.org |
| 2 | +server { |
| 3 | + listen 80; |
| 4 | + listen [::]:80; |
| 5 | + server_name subdomain.example.org; |
| 6 | + |
| 7 | + # include /etc/nginx/snippets/letsencrypt.conf; |
| 8 | + |
| 9 | + location / { |
| 10 | + return 301 https://subdomain.example.org$request_uri; |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +## Serves https://subdomain.example.org |
| 16 | +server { |
| 17 | + server_name subdomain.example.org; |
| 18 | + listen 443 ssl http2; |
| 19 | + listen [::]:443 ssl http2; |
| 20 | + # gzip off; |
| 21 | + gzip on; |
| 22 | + gzip_disable "msie6"; |
| 23 | + |
| 24 | + gzip_comp_level 6; |
| 25 | + gzip_min_length 1100; |
| 26 | + gzip_buffers 16 8k; |
| 27 | + gzip_proxied any; |
| 28 | + gzip_types |
| 29 | + # text/plain |
| 30 | + text/css |
| 31 | + text/js |
| 32 | + # text/xml |
| 33 | + text/javascript |
| 34 | + application/javascript |
| 35 | + application/x-javascript; |
| 36 | + # application/json |
| 37 | + # application/xml |
| 38 | + # application/rss+xml |
| 39 | + # image/svg+xml; |
| 40 | + |
| 41 | + ssl_certificate /etc/letsencrypt/live/subdomain.example.org/fullchain.pem; |
| 42 | + ssl_certificate_key /etc/letsencrypt/live/subdomain.example.org/privkey.pem; |
| 43 | + ssl_trusted_certificate /etc/letsencrypt/live/subdomain.example.org/fullchain.pem; |
| 44 | + |
| 45 | + ssl_client_certificate /etc/letsencrypt/cloudflare/origin-pull-ca.pem; |
| 46 | + ssl_verify_client on; |
| 47 | + |
| 48 | + include /etc/nginx/snippets/ssl.conf; |
| 49 | + # ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # recommended by Certbot |
| 50 | + ssl_dhparam /etc/letsencrypt/dhparam.pem; |
| 51 | + |
| 52 | + ## server_tokens off; # already in /etc/nginx/snippets/ssl.conf |
| 53 | + |
| 54 | + ## add_header X-Frame-Options DENY; # already in /etc/nginx/snippets/ssl.conf |
| 55 | + ## add_header X-Content-Type-Options nosniff always; # already in /etc/nginx/snippets/ssl.conf |
| 56 | + # add_header X-Xss-Protection "1"; |
| 57 | + ## add_header X-Xss-Protection "1; mode=block" always; # already in /etc/nginx/snippets/ssl.conf |
| 58 | + |
| 59 | + # WARNING! This header must be carefully planned before deploying it on production website |
| 60 | + # as it could easily break stuff and prevent a website to load it’s content! |
| 61 | + # for more info, read https://letsecure.me/secure-web-deployment-with-lets-encrypt-and-nginx/ |
| 62 | + # https://content-security-policy.com/ |
| 63 | + # https://scotthelme.co.uk/content-security-policy-an-introduction/ |
| 64 | + add_header Content-Security-Policy "script-src 'self' https://*.google-analytics.com https://*.googleapis.com https://*.twimg.com https://*.google.com https://www.google.com/recaptcha/api/js/recaptcha_ajax.js https://freegeoip.net https://*.ravenjs.com https://*.sentry.io https://*.disqus.com https://*.amazonaws.com https://*.time.ly https://*.googletagmanager.com https://api.reftagger.com https://reftaggercdn.global.ssl.fastly.net https://*.social9.com https://*.sermonaudio.com https://*.tockify.com https://*.addthis.com https://*.gstatic.com https://*.quotery.com https://*.openweathermap.org https://openweathermap.org https://*.mapbox.com https://*.cloudflare.com https://*.maxcdn.com https://*.bbci.co.uk https://browser-update.org https://*.bbc.co.uk https://*.facebook.com https://*.facebook.net https://*.twitter.com https://*.youtube.com https://cdn.jsdelivr.net 'unsafe-inline' 'unsafe-eval'"; |
| 65 | + # add_header Content-Security-Policy "default-src 'self'"; |
| 66 | + # add_header Content-Security-Policy "default-src 'self'; script-src 'self' *.google-analytics.com"; |
| 67 | + add_header Referrer-Policy strict-origin-when-cross-origin; |
| 68 | + |
| 69 | + ## ssl_stapling on; # already in /etc/nginx/snippets/ssl.conf |
| 70 | + ## ssl_stapling_verify on; # already in /etc/nginx/snippets/ssl.conf |
| 71 | + |
| 72 | + sendfile on; |
| 73 | + client_max_body_size 50M; |
| 74 | + keepalive_timeout 0; |
| 75 | + |
| 76 | + location = /favicon.ico { access_log off; log_not_found off; } |
| 77 | + |
| 78 | + # location /ico { |
| 79 | + # alias /path/to/your/subdomain.example.org/{{cookiecutter.project_slug}}/static/ico; |
| 80 | + # } |
| 81 | + |
| 82 | + location /static { |
| 83 | + etag on; |
| 84 | + expires 7d; |
| 85 | + access_log off; |
| 86 | + add_header Cache-Control "no-cache, public"; |
| 87 | + alias /path/to/your/subdomain.example.org/{{cookiecutter.project_slug}}/staticfiles; |
| 88 | + } |
| 89 | + |
| 90 | + location /files/ { |
| 91 | + etag on; |
| 92 | + expires 7d; |
| 93 | + access_log off; |
| 94 | + add_header Cache-Control "no-cache, public"; |
| 95 | + alias /path/to/your/subdomain.example.org/{{cookiecutter.project_slug}}/files/; |
| 96 | + } |
| 97 | + |
| 98 | + location / { |
| 99 | + include uwsgi_params; |
| 100 | + uwsgi_pass unix:/run/uwsgi/subdomain.example.org_production_app.sock; |
| 101 | + |
| 102 | + proxy_set_header Host $http_host; |
| 103 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 104 | + # proxy_set_header X-Forwarded-Proto https; # <- |
| 105 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 106 | + proxy_redirect off; |
| 107 | + |
| 108 | + } |
| 109 | + |
| 110 | + #browser caching of static assets |
| 111 | + # location ~* \.(jpg|jpeg|svg|png|gif|ico)$ { |
| 112 | + # etag on; |
| 113 | + # expires 7d; |
| 114 | + # access_log off; |
| 115 | + # add_header Cache-Control "no-cache, public"; |
| 116 | + # } |
| 117 | + |
| 118 | + #browser caching of css and js |
| 119 | + # location ~* \.(css|js|gz)$ { |
| 120 | + # etag on; |
| 121 | + # expires 2d; |
| 122 | + # access_log off; |
| 123 | + # add_header Cache-Control "no-cache, public"; |
| 124 | + # } |
| 125 | + |
| 126 | + # add one directive for each http status code |
| 127 | + error_page 400 /ErrorPages/custom_400.html; |
| 128 | + error_page 401 /ErrorPages/custom_401.html; |
| 129 | + error_page 403 /ErrorPages/custom_403.html; |
| 130 | + error_page 404 /ErrorPages/custom_404.html; |
| 131 | + error_page 500 /ErrorPages/custom_500.html; |
| 132 | + error_page 501 /ErrorPages/custom_501.html; |
| 133 | + error_page 502 /ErrorPages/custom_502.html; |
| 134 | + error_page 503 /ErrorPages/custom_503.html; |
| 135 | + error_page 504 /ErrorPages/custom_504.html; |
| 136 | + |
| 137 | + # redirect the virtual ErrorPages path the real path |
| 138 | + location /ErrorPages/ { |
| 139 | + alias /path/to/your/subdomain.example.org/{{cookiecutter.project_slug}}/templates/nginx/; |
| 140 | + internal; |
| 141 | + } |
| 142 | + |
| 143 | + access_log /path/to/your/subdomain.example.org/.logs/subdomain.example.org_production_access_log; |
| 144 | + error_log /path/to/your/subdomain.example.org/.logs/subdomain.example.org_production_error_log; |
| 145 | +} |
0 commit comments