Skip to content

Instantly share code, notes, and snippets.

@anil826
Last active November 19, 2016 19:50
Show Gist options
  • Save anil826/efd67134bd24ba1d03f59425be42c635 to your computer and use it in GitHub Desktop.
Save anil826/efd67134bd24ba1d03f59425be42c635 to your computer and use it in GitHub Desktop.
SSL setup Nginx: on NodeJs application with multiple ports
# Location of this file : /etc/nginx/sites-available/default
# This configuration for NodeJs application but the configuration is same for other framework also like ruby-on-rails.
# Make sure if you have AWS EC2 instance then please open the HTTPS port to serve the application on Https protocols.
# Also if you need extra port on same domain enable thoes port over AWS EC2 instance.
# In this configuration I am using same domain but with different port.
server {
listen 80;
server_name your.domain.com;
# return 301 https://$server_name$request_uri;
location / {
proxy_pass http://127.0.0.1:8081/;
}
}
server {
listen 443;
ssl on;
ssl_certificate /etc/nginx/ssl_certs/xxx_xxx_example.crt;
ssl_certificate_key /etc/nginx/ssl_certs/xxx_example.key;
server_name your.domain.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
# This is for the other node Js backend server to deal with mongodb API
server {
listen 8082;
ssl on;
ssl_certificate /etc/nginx/ssl_certs/xxxx_example.crt;
ssl_certificate_key /etc/nginx/ssl_certs/xxxx_example.key;
server_name your.domain.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://localhost:7001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment