我们有一个 Angular SPA 应用程序,需要更改其基本路径
www.site.com 至 www.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)