|
| 1 | +# Full nginx configuration with SSL certificate for nginx running on host machine |
| 2 | +# Requires a registered domain name, letsencrypt SSL certificates |
| 3 | +# and local client/server apps (running in containers or manually installed on host) |
| 4 | + |
| 5 | +server { |
| 6 | + listen 80; |
| 7 | + listen [::]:80; |
| 8 | + server_name www.<YOUR.DOMAIN.COM.HERE>; |
| 9 | + return 301 https://<YOUR.DOMAIN.COM.HERE>$request_uri; |
| 10 | +} |
| 11 | + |
| 12 | +server { |
| 13 | + listen 80; |
| 14 | + listen [::]:80; |
| 15 | + server_name <YOUR.DOMAIN.COM.HERE>; |
| 16 | + return 301 https://<YOUR.DOMAIN.COM.HERE>$request_uri; |
| 17 | +} |
| 18 | + |
| 19 | +server { |
| 20 | + listen 443 ssl; |
| 21 | + server_name www.<YOUR.DOMAIN.COM.HERE>; |
| 22 | + ssl_certificate /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/fullchain.pem; |
| 23 | + ssl_certificate_key /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/privkey.pem; |
| 24 | + return 301 https://<YOUR.DOMAIN.COM.HERE>$request_uri; |
| 25 | +} |
| 26 | + |
| 27 | +server { |
| 28 | + listen 443 ssl http2; |
| 29 | + listen [::]:443 ssl http2; |
| 30 | + |
| 31 | + server_name <YOUR.DOMAIN.COM.HERE>; |
| 32 | + server_tokens off; |
| 33 | + |
| 34 | + # Available methods |
| 35 | + add_header Allow 'GET, POST, PATCH, DELETE, HEAD' always; |
| 36 | + add_header X-XSS-Protection '1; mode=block'; |
| 37 | + |
| 38 | + if ( $request_method !~ ^(GET|POST|PATCH|DELETE|HEAD)$ ) { |
| 39 | + return 405; |
| 40 | + } |
| 41 | + |
| 42 | + ssl_certificate /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/fullchain.pem; |
| 43 | + ssl_certificate_key /etc/letsencrypt/live/<YOUR.DOMAIN.COM.HERE>/privkey.pem; |
| 44 | + |
| 45 | + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
| 46 | + ssl_prefer_server_ciphers on; |
| 47 | + ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; |
| 48 | + ssl_dhparam '/etc/pki/nginx/dhparams.pem'; |
| 49 | + |
| 50 | + add_header Strict-Transport-Security 'max-age=63072000; includeSubDomains' always; |
| 51 | + |
| 52 | + # gzip comppression settings |
| 53 | + gzip on; |
| 54 | + gzip_disable 'msie6'; |
| 55 | + |
| 56 | + gzip_vary on; |
| 57 | + gzip_proxied any; |
| 58 | + gzip_comp_level 6; |
| 59 | + gzip_buffers 16 8k; |
| 60 | + gzip_http_version 1.1; |
| 61 | + gzip_min_length 0; |
| 62 | + gzip_types text/plain application/javascript text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype; |
| 63 | + |
| 64 | + # Reverse proxy to the client website |
| 65 | + # Requires the client service running on http://<MACHINE_PRIVATE_IP>:3000 (from a container or manually installed on host) |
| 66 | + location / { |
| 67 | + proxy_pass http://<MACHINE_PRIVATE_IP>:3000; |
| 68 | + proxy_set_header Host $host; |
| 69 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 70 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 71 | + proxy_set_header X-Real-IP $remote_addr; |
| 72 | + proxy_cache_bypass $http_upgrade; |
| 73 | + |
| 74 | + # For websockets |
| 75 | + proxy_http_version 1.1; |
| 76 | + proxy_set_header Connection 'upgrade'; |
| 77 | + proxy_set_header Upgrade $http_upgrade; |
| 78 | + proxy_read_timeout 600s; |
| 79 | + } |
| 80 | + |
| 81 | + # Reverse proxy to the backend API server |
| 82 | + # Requires the backend service running on http://<MACHINE_PRIVATE_IP>:3001 (from a container or manually installed on host) |
| 83 | + location /api { |
| 84 | + proxy_pass http://<MACHINE_PRIVATE_IP>:3001; |
| 85 | + proxy_set_header Host $host; |
| 86 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 87 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 88 | + proxy_set_header X-Real-IP $remote_addr; |
| 89 | + proxy_cache_bypass $http_upgrade; |
| 90 | + |
| 91 | + # For websockets |
| 92 | + proxy_http_version 1.1; |
| 93 | + proxy_set_header Connection 'upgrade'; |
| 94 | + proxy_set_header Upgrade $http_upgrade; |
| 95 | + proxy_read_timeout 600s; |
| 96 | + } |
| 97 | + |
| 98 | + # Other error pages |
| 99 | + error_page 500 502 503 504 /50x.html; |
| 100 | + location = /50x.html { |
| 101 | + root /usr/share/nginx/html; |
| 102 | + } |
| 103 | +} |
0 commit comments