近期在搭建本身的簡單博客系統,在本地能夠先後臺分離的運行,可是部署到服務器就老是會404,最後在react官網問答上面找到了答案。
1.react設置了項目代理html
package.json ...//其餘部分省略 "proxy": "http://www.iamcrawler.cn"
2 npm run buildreact
3.服務器nginx配置:nginx
server { listen 80 ; server_name localhost:4000; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { root /react/build; index index.htm index.html; } location /api/ { proxy_pass http://127.0.0.1:4000; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { }
1.第一個localtion /: 前臺地址
2.第二個location /api/ 後臺帶/api的請求地址 npm
附上原問答地址:http://react-china.org/t/reac...json