Skip to content

Instantly share code, notes, and snippets.

@symant233
Forked from namdau/vue-nginx.conf
Created July 18, 2021 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save symant233/e296480a5a94d99891e69565b6cb9aaf to your computer and use it in GitHub Desktop.
Save symant233/e296480a5a94d99891e69565b6cb9aaf to your computer and use it in GitHub Desktop.
Nginx config for Vuejs project with an API upstream
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