在nginx裡配置了以下配置後, 可能首頁沒有問題,但連結其他會出現(404)
location / {
root D:\Test\exprice\dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
location ^~/api/ {
proxy_pass http://39.105.109.245:8080/;
}
為了解決404,需要通過以下兩種方式:
1、官網推薦
location / {
root D:\Test\exprice\dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
2、比對errpr_page
location /{
root /data/nginx/html;
index index.html index.htm;
error_page 404 /index.html;
}