-
-
Save mygoare/7692f5e508d81c4b587ffd3ad2bd6e49 to your computer and use it in GitHub Desktop.
Nginx config for Vuejs project with an API upstream
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
server { | |
server_name default_server; | |
# This is for Let's Encrypt certification renewal | |
include /etc/nginx/snippets/letsencrypt.conf; | |
# Redirect to https | |
location / { | |
return 301 https://$server_name$request_uri; | |
} | |
} | |
upstream api_server { | |
server localhost:7000; # API upstream | |
} | |
server { | |
# SSL configuration | |
ssl on; | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
include /etc/nginx/snippets/ssl-app.conf; | |
include /etc/nginx/snippets/ssl-params.conf; | |
access_log /var/log/nginx/app_access.log; | |
error_log /var/log/nginx/app_error.log; | |
server_name default_server; | |
root /path/to/dist/; | |
index index.html; | |
location = /favicon.ico { | |
log_not_found off; | |
access_log off; | |
} | |
location = /robots.txt { | |
allow all; | |
log_not_found off; | |
access_log off; | |
} | |
location / { | |
try_files $uri $uri/ @rewrites; | |
} | |
location @rewrites { | |
rewrite ^(.+)$ /index.html last; | |
} | |
location /api { | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-Proto https; | |
proxy_set_header X-Forwarded-For $remote_addr; | |
proxy_set_header X-Forwarded-Host $remote_addr; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_pass https://api_server/api; | |
proxy_ssl_session_reuse off; | |
proxy_redirect off; | |
} | |
location ~ /\. { | |
deny all; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment