Skip to content

Instantly share code, notes, and snippets.

@wmzy
Last active February 28, 2024 04:41
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save wmzy/f4f540f3ee30fd632698c7d625cb219e to your computer and use it in GitHub Desktop.
Save wmzy/f4f540f3ee30fd632698c7d625cb219e to your computer and use it in GitHub Desktop.
spa nginx config | 单页应用 nginx 配置
upstream backend {
server 127.0.0.1:3000;
}
server {
listen 80;
server_name your.hostname.com;
proxy_set_header Host $http_host;
access_log /tmp/test-access.log debug;
rewrite_log on;
root /home/work/project/path/public;
location / {
try_files $uri /index.html;
index index.html index.htm;
}
location /index.html {
add_header Cache-Control "no-cache, no-store, must-revalidate";
}
location ^~ /assets/ {
add_header Cache-Control "public,max-age=31536000";
# Allow cross origin access
add_header Access-Control-Expose-Headers "Access-Control-Allow-Origin";
add_header Access-Control-Allow-Origin "*";
}
location /api {
proxy_pass http://backend;
}
# server sent event
location ~ /sent-events/(.*) {
proxy_pass http://backend/$1;
proxy_set_header Host $host;
proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_buffering off;
proxy_cache off;
chunked_transfer_encoding off;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment