我有一个在 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/(.*) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass_request_headers on;
proxy_pass <ENV_API_URL>/$1$is_args$args;
}
}
Run Code Online (Sandbox Code Playgroud)
您应该使用 analias来直接替换您想要的路径。
location = /register {
alias /public/xyz/index.html;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
217 次 |
| 最近记录: |