主要是router問題,兩個解決方案
一個是修改angular項目的router選項,一個是修改Nginx的route 選項
一般情況下項目部署了,不願意修改angular項目的router選項,所以
修改nginx 的選項:
第一步
查看nginx的配置文件位置
docker exec -it yourContainerId /bin/sh
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
第二步
文件cp
docker cp yourContainerId:/etc/nginx/nginx.conf nginx.conf
打開復制到當前路徑下的文件:nginx.conf,其他建議就是添加:
location /myangular {
alias /html/myangular;#angular項目所在目錄
index index.html index.htm;
try_files $uri $uri/ /index.html =404;#主要是這一行
}
但不一定起作用,主要是這句配置:
include /etc/nginx/conf.d/*.conf;
這就需要重復上述步驟進入exec cp /etc/nginx/conf.d/下的conf文件修改:
還是加上這一行:
try_files $uri $uri/ /index.html;
最后
執行cp命令,復制回去,重新啟動container就ok了。
docker cp default.conf yourContainerId:/etc/nginx/conf.d/default.conf
angular項目中的解決辦法
在root.module.ts加入: