Created
August 11, 2020 15:59
-
-
Save shivamgpt38/7e4467c6e47637a0ac52d335cfe319a7 to your computer and use it in GitHub Desktop.
Nginx configuration for NodeJs+socket.io+let's encrypt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
@shivamgpt38 This config file really made my day, as we were really struggling to make websocket works on nginx, spent almost 2-3 days to find solution, but finally found yours config, which is working like a charm, kudos to you.