Advertisement
Guest User

nginx.conf

a guest
Apr 26th, 2023
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 7.48 KB | Source Code | 0 0
  1. # Generated by nginxconfig.io
  2. # See nginxconfig.txt for the configuration share link
  3.  
  4. user                 nginx;
  5. pid                  /tmp/nginx.pid;
  6. worker_processes     auto;
  7. worker_rlimit_nofile 65535;
  8.  
  9. # Load modules
  10. include              /etc/nginx/modules-enabled/*.conf;
  11.  
  12. events {
  13.     multi_accept       on;
  14.     worker_connections 65535;
  15. }
  16.  
  17. http {
  18.     charset                utf-8;
  19.     sendfile               on;
  20.     tcp_nopush             on;
  21.     tcp_nodelay            on;
  22.     server_tokens          off;
  23.     log_not_found          off;
  24.     types_hash_max_size    2048;
  25.     types_hash_bucket_size 64;
  26.     client_max_body_size   16M;
  27.  
  28.     # MIME
  29.     include                mime.types;
  30.     default_type           application/octet-stream;
  31.  
  32.     # Logging
  33.     access_log             off;
  34.     error_log              /var/log/nginx/error.log error;
  35.  
  36.     # Limits
  37.     limit_req_log_level    warn;
  38.     limit_req_zone         $binary_remote_addr zone=login:10m rate=10r/m;
  39.  
  40.     # SSL
  41.     ssl_session_timeout    1d;
  42.     ssl_session_cache      shared:SSL:10m;
  43.     ssl_session_tickets    off;
  44.  
  45.     # Diffie-Hellman parameter for DHE ciphersuites
  46.     ssl_dhparam            /etc/ssl/certs/dhparam.pem;
  47.  
  48.     # Mozilla Intermediate configuration
  49.     ssl_protocols          TLSv1.2 TLSv1.3;
  50.     ssl_ciphers            ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  51.  
  52.     # OCSP Stapling
  53.     ssl_stapling           on;
  54.     ssl_stapling_verify    on;
  55.     resolver               1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
  56.     resolver_timeout       2s;
  57.  
  58.     # Connection header for WebSocket reverse proxy
  59.     map $http_upgrade $connection_upgrade {
  60.         default upgrade;
  61.         ""      close;
  62.     }
  63.  
  64.     map $remote_addr $proxy_forwarded_elem {
  65.  
  66.         # IPv4 addresses can be sent as-is
  67.         ~^[0-9.]+$        "for=$remote_addr";
  68.  
  69.         # IPv6 addresses need to be bracketed and quoted
  70.         ~^[0-9A-Fa-f:.]+$ "for=\"[$remote_addr]\"";
  71.  
  72.         # Unix domain socket names cannot be represented in RFC 7239 syntax
  73.         default           "for=unknown";
  74.     }
  75.  
  76.     map $http_forwarded $proxy_add_forwarded {
  77.  
  78.         # If the incoming Forwarded header is syntactically valid, append to it
  79.         "~^(,[ \\t]*)*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*([ \\t]*,([ \\t]*([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?(;([!#$%&'*+.^_`|~0-9A-Za-z-]+=([!#$%&'*+.^_`|~0-9A-Za-z-]+|\"([\\t \\x21\\x23-\\x5B\\x5D-\\x7E\\x80-\\xFF]|\\\\[\\t \\x21-\\x7E\\x80-\\xFF])*\"))?)*)?)*$" "$http_forwarded, $proxy_forwarded_elem";
  80.  
  81.         # Otherwise, replace it
  82.         default "$proxy_forwarded_elem";
  83.     }
  84.  
  85.     # Load configs
  86.     include /etc/nginx/conf.d/*.conf;
  87.  
  88.     # api.ch.com
  89.     server {
  90.         listen                               443 ssl http2 reuseport;
  91.         listen                               [::]:443 ssl http2 reuseport;
  92.         server_name                          www.api.ch.com;
  93.         root                                 /var/www/_letsencrypt;
  94.  
  95.         # SSL
  96.         ssl_certificate                      /etc/letsencrypt/live/api.ch.com/fullchain.pem;
  97.         ssl_certificate_key                  /etc/letsencrypt/live/api.ch.com/privkey.pem;
  98.         ssl_trusted_certificate              /etc/letsencrypt/live/api.ch.com/chain.pem;
  99.  
  100.         # security headers
  101.         add_header X-XSS-Protection          "1; mode=block" always;
  102.         add_header X-Content-Type-Options    "nosniff" always;
  103.         add_header Referrer-Policy           "no-referrer-when-downgrade" always;
  104.         add_header Content-Security-Policy   "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';" always;
  105.         add_header Permissions-Policy        "interest-cohort=()" always;
  106.         add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
  107.  
  108.         # . files
  109.         location ~ /\.(?!well-known) {
  110.             deny all;
  111.         }
  112.  
  113.         # security.txt
  114.         location /security.txt {
  115.             return 301 /.well-known/security.txt;
  116.         }
  117.  
  118.         location = /.well-known/security.txt {
  119.             alias ~/security.txt;
  120.         }
  121.  
  122.         # logging
  123.         access_log /var/log/nginx/access.log combined buffer=512k flush=1m;
  124.         error_log  /var/log/nginx/error.log error;
  125.  
  126.         # reverse proxy
  127.         location / {
  128.             proxy_pass                         http://api_server_prod:21347;
  129.             proxy_set_header Host              $host;
  130.             proxy_http_version                 1.1;
  131.             proxy_cache_bypass                 $http_upgrade;
  132.  
  133.             # Proxy SSL
  134.             proxy_ssl_server_name              on;
  135.  
  136.             # Proxy headers
  137.             proxy_set_header Upgrade           $http_upgrade;
  138.             proxy_set_header Connection        $connection_upgrade;
  139.             proxy_set_header X-Real-IP         $remote_addr;
  140.             proxy_set_header Forwarded         $proxy_add_forwarded;
  141.             proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
  142.             proxy_set_header X-Forwarded-Proto $scheme;
  143.             proxy_set_header X-Forwarded-Host  $host;
  144.             proxy_set_header X-Forwarded-Port  $server_port;
  145.  
  146.             # Proxy timeouts
  147.             proxy_connect_timeout              60s;
  148.             proxy_send_timeout                 60s;
  149.             proxy_read_timeout                 60s;
  150.         }
  151.  
  152.         # favicon.ico
  153.         location = /favicon.ico {
  154.             log_not_found off;
  155.         }
  156.  
  157.         # robots.txt
  158.         location = /robots.txt {
  159.             log_not_found off;
  160.         }
  161.  
  162.         # gzip
  163.         gzip            on;
  164.         gzip_vary       on;
  165.         gzip_proxied    any;
  166.         gzip_comp_level 6;
  167.         gzip_types      text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
  168.     }
  169.  
  170.     # non-www, subdomains redirect
  171.     server {
  172.         listen                  443 ssl http2;
  173.         listen                  [::]:443 ssl http2;
  174.         server_name             .api.ch.com;
  175.  
  176.         # SSL
  177.         ssl_certificate         /etc/letsencrypt/live/api.ch.com/fullchain.pem;
  178.         ssl_certificate_key     /etc/letsencrypt/live/api.ch.com/privkey.pem;
  179.         ssl_trusted_certificate /etc/letsencrypt/live/api.ch.com/chain.pem;
  180.  
  181.         # logging
  182.         error_log               /var/log/nginx/error.log error;
  183.         return                  301 https://www.api.ch.com$request_uri;
  184.     }
  185.  
  186.     # HTTP redirect
  187.     server {
  188.         listen      80 reuseport;
  189.         listen      [::]:80 reuseport;
  190.         server_name .api.ch.com;
  191.  
  192.         # logging
  193.         error_log   /var/log/nginx/error.log error;
  194.  
  195.         # ACME-challenge
  196.         location ^~ /.well-known/acme-challenge/ {
  197.             allow all;
  198.             root /var/www/_letsencrypt;
  199.         }
  200.  
  201.         location / {
  202.             return 301 https://www.api.ch.com$request_uri;
  203.         }
  204.     }
  205. }
  206.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement