【发布时间】:2019-06-12 22:06:08
【问题描述】:
我正在使用 nginx 进行反向代理。我正在使用别名重写目录。在我的别名目录中,我有使用 html5 路由的 Angular 2 构建文件。因此,当用户刷新页面时,它应该只重写该目录中存在的 index.html。
“控制面板被别名覆盖”
我已经尝试过“try_files $uri $uri/ /index.html =404;” 但这是指主目录中的 index.html。
我也尝试过尝试提供绝对路径,但仍然无法正常工作。
server {
listen 80;
server_name xx.xxx.xx.xxx;
location / {
proxy_pass http://localhost:4000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /control-panel {
alias /var/www/html/soundoff-admin-dev/dist;
# here rewrite should override with index.html inside "dist" directory
}
}
【问题讨论】:
-
我脑海中的
try_files $uri $uri/ /index.html =404;将转到您的/位置以获取index.html,然后它会调用您的代理。那么为什么不更改 index.html 路径以使用您的位置 -
@ShawnC。已经试过了。但不工作。在页面刷新时显示 404 错误
标签: nginx nginx-location nginx-reverse-proxy nginx-config