一、前端代理配置示例
server {
listen 80;
server_name xxx.xxxx.com www.xxx.xxxx.com;
access_log on;
charset utf-8;
location / {
root /home/test/build;
index index.html index.htm;
# error_page 403 /index.html;
# error_page 404 /index.html;
try_files $uri /index.html; #加上这句解决react 当前路由下 刷新 报404的问题
if (!-e $request_filename) {
rewrite ^.+test/(.*) /index.html last;
break;
}
}
# 前端路由代理
location /api {
rewrite ^.+api/?(.*)$ /$1 break;
proxy_pass http://xxx.xxxx.com;
}
# 错误处理重定向相对nginx路径下 html/50x.html路径
error_page 500 502 503 504 /50x.html;
# 错误处理404页面处理方式,具体根据情况配置,暴力解决线上404问题,但不能从根本上解决
error_page 404 /index.html;
# 自定义错误页面线上地址
error_page 400 http://www.baidu.com;
location = /index.html {
root /home/test/build;
}
location = /50x.html {
root html;
}
# 解决 GET /favicon.ico HTTP/1.1 404问题
location /favicon.ico{
return 200;
access_log off;
}
}
`和上面处理一样`
# /favicon.ico” failed (2: No such file or directory)
location = /favicon.ico {
log_not_found off;
access_log off;
}