您应该配置位置,以便让角度来决定路线,这也将解决重新加载问题。
location / {
root /usr/share/nginx/html;
index index.html;
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
# Old deafult, I comment this because i have SPA app look: line 55
# try_files $uri$args $uri$args/ $uri $uri/ =404;
# If the route dont exist return index.html
# This is the best option for (SPA Applications) like: React, Angular 5, Vue.js and Angular.js
try_files $uri /index.html;
}
您可以查看我的 nginx.conf 文件,其中我有一个用于 api 和 NGINX 的烧瓶服务器,用于提供角度 dist 文件。
另外,您可以查看我的存储库,其中我展示了如何使用(NGINX、Angular 5、Docker、Flask)的工作示例
https://github.com/George35mk/Docker-NGINX-NG5-Flask-Elastic
nginx.conf
# ==============================================================================
# New Config
# ==============================================================================
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
gzip on;
# Configuration for the server
server {
listen 80;
location /api {
proxy_pass http://flask_api:5000;
}
location / {
root /usr/share/nginx/html;
index index.html;
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
# Old deafult, I comment this because i have SPA app look: line 55
# try_files $uri$args $uri$args/ $uri $uri/ =404;
# If the route dont exist return index.html
# This is the best option for (SPA Applications) like: React, Angular 5, Vue.js and Angular.js
try_files $uri /index.html;
}
}
}