React或Vue应用编译为静态文件后用Nginx访问的话,需要给Nginx添加以下配置:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ @router;
}
location ^~ /api/ {
proxy_pass http://localhost:8080;
}
location @router {
rewrite ^.*$ /index.html break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}