Advertisement
kastielspb

Nginx ssl config

Feb 25th, 2019 (edited)
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 3.79 KB | None | 0 0
  1. upstream advertalist_gunicorn_server {
  2.     server unix:/run/advertalist_gunicorn/advertalist_gunicorn.socket fail_timeout=0;
  3. }
  4.  
  5. upstream advertalist_gunicorn_asgi_server {
  6.     server unix:ASGI_SOCKET fail_timeout=0;
  7. }
  8.  
  9. server {
  10.     server_name some-domain.com www.some-domain.com;
  11.     listen 80;
  12.     return 301 https://some-domain.com$request_uri;
  13. }
  14.  
  15. server {
  16.     server_name www.some-domain.com;
  17.     listen some-domain.com:443 ssl;
  18.     # or
  19.     # server_name ~^www\.(?<domain>.+)$;
  20.     # listen 443 ssl http2;
  21.    
  22.     access_log off;
  23.  
  24.     ssl_certificate /etc/letsencrypt/live/some-domain.com/fullchain.pem;
  25.     ssl_certificate_key /etc/letsencrypt/live/some-domain.com/privkey.pem;
  26.     ssl_trusted_certificate /etc/letsencrypt/live/some-domain.com/chain.pem;
  27.  
  28.     ssl_stapling on;
  29.     ssl_stapling_verify on;
  30.  
  31.     add_header Strict-Transport-Security "max-age=31536000";
  32.  
  33.     return 301 $scheme://some-domain.com$request_uri;
  34.     # or
  35.     #return 302 $scheme://$domain$request_uri;
  36. }
  37.  
  38. server {
  39.     #listen 80 default_server;
  40.     #listen [::]:80 default_server ipv6only=on;
  41.     #server_name _;
  42.  
  43.     server_name some-domain.com;
  44.     listen some-domain.com:443 ssl;
  45.     # or
  46.     #listen 443 ssl http2 default_server;
  47.     #listen [::]:443 ssl http2 default_server;
  48.  
  49.     ##if ($http_host ~ ~^www\.(.+)$) {
  50.     ##    return 302 https://$1$request_uri;
  51.     ##}
  52.  
  53.     access_log off;
  54.  
  55.     ssl_certificate /etc/letsencrypt/live/some-domain.com/fullchain.pem;
  56.     ssl_certificate_key /etc/letsencrypt/live/some-domain.com/privkey.pem;
  57.     ssl_trusted_certificate /etc/letsencrypt/live/some-domain.com/chain.pem;
  58.  
  59.     ssl_stapling on;
  60.     ssl_stapling_verify on;
  61.  
  62.     add_header Strict-Transport-Security "max-age=31536000";
  63.  
  64.     error_log /var/log/nginx/error.log crit;
  65.  
  66.     open_file_cache max=200000 inactive=20s;
  67.     open_file_cache_valid 30s;
  68.     open_file_cache_min_uses 2;
  69.     open_file_cache_errors on;
  70.  
  71.     access_log off;
  72.     sendfile on;
  73.     tcp_nopush on;
  74.     tcp_nodelay on;
  75.  
  76.     gzip on;
  77.     gzip_comp_level    5;
  78.     gzip_min_length 256;
  79.     gzip_proxied any;
  80.     gzip_types
  81.       application/atom+xml
  82.        application/javascript
  83.        application/json
  84.        application/ld+json
  85.        application/manifest+json
  86.        application/rss+xml
  87.        application/vnd.geo+json
  88.        application/vnd.ms-fontobject
  89.        application/x-font-ttf
  90.        application/x-web-app-manifest+json
  91.        application/xhtml+xml
  92.        application/xml
  93.        font/opentype
  94.        image/bmp
  95.        image/svg+xml
  96.        image/x-icon
  97.        text/cache-manifest
  98.        text/css
  99.        text/plain
  100.        text/vcard
  101.        text/vnd.rim.location.xloc
  102.        text/vtt
  103.        text/x-component
  104.        text/x-cross-domain-policy;
  105.  
  106.     gzip_disable msie6;
  107.  
  108.     keepalive_timeout 30;
  109.     keepalive_requests 100000;
  110.     reset_timedout_connection on;
  111.     client_body_timeout 10;
  112.     send_timeout 2;
  113.  
  114.     client_max_body_size 4G;
  115.  
  116.     # Your Django project's media files - amend as required
  117.     location /uploads  {
  118.         alias /home/advertalist/advertalist/advertalist/server/app/uploads;
  119.         expires 30d;
  120.     }
  121.  
  122.     # your Django project's static files - amend as required
  123.     location /static {
  124.         alias /home/advertalist/advertalist/advertalist/server/app/static;
  125.         expires 30d;
  126.     }
  127.  
  128.     location /.well-known {
  129.         root /var/www/html;
  130.     }    
  131.  
  132.     # gunicorn
  133.     location / {
  134.         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  135.         proxy_set_header X-Forwarded-Proto $scheme;
  136.         proxy_set_header Host $http_host;
  137.         proxy_redirect off;
  138.         proxy_pass http://advertalist_gunicorn_server;
  139.     }
  140.  
  141.     # uwsgi
  142.     # location / {
  143.     #     uwsgi_pass 0.0.0.0:9000;
  144.     #     include uwsgi_params;
  145.     # }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement