小编van*_*ert的帖子

在 /register 上显示静态 html 文件

我有一个在 nginx 上运行的 Web 应用程序(使用 VueJS CLI 编写)。

对此应用程序的所有请求(除了/api)都由 root 处理index.html(因为它使用前端路由)。我想为此规则添加另一个例外,以便当我们转到/register它时会将我们重定向到其他一些静态公共 html 文件(与此 VueJS 应用程序无关,但位于同一项目/目录下)。

换句话说,我想重定向/register/public/xyz/index.html但不更改浏览器地址栏中显示的 URL

我试图添加location = /register规则,但它似乎不起作用,/register它仍然不断将我重定向到/app/dist/index.html.

我的 nginx.conf:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /app/dist;
    index index.html;

    server_name localhost;

    location = /register {
        root /public/xyz;
        index index.html
    }
    location / {
        try_files $uri $uri/ /index.html;
        add_header Cache-Control no-cache;
        expires 0;
    }
    location ~ ^/api/(.*) …
Run Code Online (Sandbox Code Playgroud)

nginx

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

标签 统计

nginx ×1