Last active
October 26, 2019 08:53
-
-
Save sarangnx/06648a7256c4cd75520c5cd8708c3240 to your computer and use it in GitHub Desktop.
Nginx configuration example
This file contains hidden or 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
#redirect all request to port 80 to 443 ( http -> https ) | |
server { | |
listen 80; | |
server_name servername; | |
return 301 https://$host$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name servername; | |
# SSL CERTIFICATE | |
ssl_certificate /etc/letsencrypt/live/servername.com/cert.pem; | |
ssl_certificate_key /etc/letsencrypt/live/servername.com/privkey.pem; | |
# Route request with /api/ to the nodejs api server | |
location /api/ { | |
proxy_pass http://127.0.0.1:3000/api/; | |
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 part is required for correct routing of socket.io connections | |
location /socket.io/ { | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection "upgrade"; | |
proxy_http_version 1.1; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $host; | |
proxy_pass http://127.0.0.1:3000; | |
} | |
# images are placed in the serverroot/images folder | |
location /images/ { | |
root /home/user/serverroot/; | |
} | |
# The client web app dist directory | |
location / { | |
root /home/user/vueroot/dist; | |
# fallback for history mode | |
try_files $uri $uri/ /index.html; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment