Skip to content

Instantly share code, notes, and snippets.

@asonnino
Last active December 12, 2023 02:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save asonnino/11c1c825110f0a6d55bea25feb0973f6 to your computer and use it in GitHub Desktop.
Save asonnino/11c1c825110f0a6d55bea25feb0973f6 to your computer and use it in GitHub Desktop.
Example of Nginx configuration file for HTTPS proxy to a nodejs server.
#
# nginx configuration file for HTTPS proxy to a nodejs server.
# 1. obtain an SSL certificate from letsencrypt (https://letsencrypt.org)
# 2. copy this file to /etc/nginx/site-available;
# 3. create an alias for nginx: ln -s /etc/nginx/site-available/example.com /etc/nginx/site-enabled
# 4. restart nginx: sudo service nginx restart
#
# HTTP - redirect all requests to HTTPS:
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
server_name <example.com>; # replace <example.com> by your domain name
return 301 https://$host$request_uri;
}
# HTTPS - proxy requests on to local Node.js app:
server {
listen 443;
server_name <example.com>; # replace <example.com> by your domain name
client_max_body_size 4000M; # maximum upload size
proxy_request_buffering off; # stream multipart form to the backend in real-time
ssl on;
# Use certificate and key provided by Let's Encrypt:
ssl_certificate /etc/letsencrypt/live/<example.com>/fullchain.pem; # replace <example.com> by your domain name
ssl_certificate_key /etc/letsencrypt/live/<example.com>/privkey.pem; # replace <example.com> by your domain name
ssl_session_timeout 5m;
ssl_protocols TLSv1.2 TLSv1.23;
ssl_prefer_server_ciphers on;
ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
ssl_dhparam /etc/ssl/certs/dhparam.pem;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; ";
# Pass requests for / to the nodejs server:
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://localhost:<port>; # replace <port> with the port number on which your nodejs server runs
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
}
@aviatorBeijing
Copy link

listen 443 ssl;
http2 on;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment