user root; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 8980; server_name 127.0.0.1; client_max_body_size 200m; root /usr/local/web; index index.html; location / { # 此处的 @router 实际上是引用下面的转发,否则在 Vue 路由刷新时可能会抛出 404 try_files $uri $uri/ @router; # 请求指向的首页 index index.html; } # 由于路由的资源不一定是真实的路径,无法找到具体文件 # 所以需要将请求重写到 index.html 中,然后交给真正的 Vue 路由处理请求资源 location @router { rewrite ^.*$ /index.html last; } location /week/ { proxy_pass http://10.25.17.26:8981/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; add_header Set-Cookie "Secure"; proxy_cookie_path / "/; httponly; secure; SameSite=Strict"; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }