Skip to content

Instantly share code, notes, and snippets.

@kazi-shahin
Forked from shivamgpt38/nginx.conf
Created September 13, 2022 06:23
Show Gist options
  • Save kazi-shahin/cf3ed75ed9cd7fc44a2e57d76e8300ad to your computer and use it in GitHub Desktop.
Save kazi-shahin/cf3ed75ed9cd7fc44a2e57d76e8300ad to your computer and use it in GitHub Desktop.
Nginx configuration for NodeJs+socket.io+let's encrypt
upstream my-domain {
server 127.0.0.1:8080; // nodejs and socketio running on same port. chnage or create new upstream for socket if socket running on different port
}
server {
listen 80;
server_name *.example.com; //change domain
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name *.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; //handle by let's encrypt
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;//handle by let's encrypt
include /etc/letsencrypt/options-ssl-nginx.conf;//handle by let's encrypt
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;//handle by let's encrypt
location / {
proxy_pass http://my-domain;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
add_header Front-End-Https on;
}
location /socket.io/ {
proxy_pass http://my-domain;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment