小编K J*_*son的帖子

Nginx SPA 提供静态文件、代理 API 调用和重写到 /index.html

所以,我想要一个 nginx.conf ......

  1. 直接服务所有 /static 请求
  2. 将所有 /api 请求代理到另一个本地服务器(端口 8200)
  3. 为所有其他请求提供 /index.html(因此,/contact/123 将真正提供 /index.html)

这是我目前的配置...

server {
listen                      80;
server_name                 www.xyz.io;
root                        /opt/xyz/www;

location / {
    try_files $uri $uri/ @backend;
}

location @backend {
    proxy_pass http://127.0.0.1:8200;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
}
Run Code Online (Sandbox Code Playgroud)

}

我真的不清楚如何让所有其他请求提供 /index.html 服务。想法?

nginx

2
推荐指数
1
解决办法
2787
查看次数

标签 统计

nginx ×1