小编use*_*398的帖子

带有自定义 --base-href 和 Nginx 路由的 Angular SPA

我们有一个 Angular SPA 应用程序,需要更改其基本路径

www.site.comwww.site.com/app

我们添加--base-href=/app到 ng build 命令中

RUN ng build --output-path=dist --base-href=/app/ --prod
Run Code Online (Sandbox Code Playgroud)

我们的 nginx 配置中有这样的内容:

location / {
 try_files $uri $uri/ /index.html;
}
Run Code Online (Sandbox Code Playgroud)

我们把它改为

location /app/ {
 root /usr/share/nginx/html/app;
 try_files $uri $uri/ /app/index.html;
}
Run Code Online (Sandbox Code Playgroud)

访问该网站localhost/consumerhub会抛出 500 错误。这是我在日志中看到的:

2019/10/15 19:53:51 [error] 7#7: *1 rewrite or internal redirection cycle while internally redirecting to "/app/index.html", client: 172.17.0.1, server: , request: "GET /app/ HTTP/1.1", host: "localhost:9182"
172.17.0.1 - - [15/Oct/2019:19:53:51 +0000] "GET /app/ HTTP/1.1" 500 …
Run Code Online (Sandbox Code Playgroud)

nginx angular

9
推荐指数
1
解决办法
8160
查看次数

标签 统计

angular ×1

nginx ×1