Skip to content

Instantly share code, notes, and snippets.

@SarasArya
Last active April 10, 2019 19:16
Show Gist options
  • Save SarasArya/4a5a07db6529ef10ce82a69a1ba18253 to your computer and use it in GitHub Desktop.
Save SarasArya/4a5a07db6529ef10ce82a69a1ba18253 to your computer and use it in GitHub Desktop.
Ngnix Configuration that works when you have a server running at some port
server {
listen 80;
server_name <your server name>;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name <your server name>;
ssl_certificate /etc/letsencrypt/live/<your website name>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<your website name>/privkey.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
location / {
proxy_set_header X-Real-IP $remote_addr; # to get the real IP not the proxy one
proxy_set_header HOST $http_host; # This config is making it so that the Host header that the client sent nginx is sent on to the backend
proxy_set_header X-NginX-Proxy true; # just a marker, saying Nginx proxy is used. Not really useful
proxy_pass http://localhost:<your port>; # where you want it to forward the request to
proxy_http_version 1.1; # set HTTP version
proxy_set_header Upgrade $http_upgrade; # For Websocket
proxy_set_header Connection "upgrade"; # For Websocket
proxy_redirect off; # For Websocket
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment