[英]React production using react-app-rewired nginx
I have tried to deploy my app on heroku and it work normally. 我尝试将我的应用程序部署在heroku上,并且正常运行。 But when I build my app using react-app-rewired script and deploy it to my server using nginx. 但是当我使用react-app-rewired脚本构建我的应用程序并使用nginx将其部署到我的服务器时。 When access my app, it still work fine but if I reload page with contextPath: http://35.240.229.243/products it throws 404 error. 访问我的应用程序时,它仍然可以正常工作,但是如果我使用contextPath重新加载页面:http: //35.240.229.243/products,则会引发404错误。 You can access my app in http://35.240.229.243 to test. 您可以在http://35.240.229.243中访问我的应用进行测试。 I am using react-router with history. 我正在使用带有历史的react-router。 Help me thanks 帮帮我谢谢
First you need to find default nginx conf file and disable it, by default it will be under /etc/nginx/sites-enabled/default
首先,您需要找到默认的nginx conf文件并将其禁用,默认情况下它将位于/etc/nginx/sites-enabled/default
sudo rm -rf /etc/nginx/sites-enabled/default
and create new file under /etc/nginx/sites-available/
并在/etc/nginx/sites-available/
下创建新文件
sudo touch /etc/nginx/sites-enabled/default/redbox
and use vim or nano to put this text into new conf file redbox
, 并使用vim或nano将此文本放入新的conf文件redbox
,
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}
and enable it 并启用它
sudo ln -s /etc/nginx/sites-available/redbox /etc/nginx/sites-enabled/redbox
next, make sure that there are no syntax errors in Nginx files, 接下来,请确保Nginx文件中没有语法错误,
sudo nginx -t
If no problems were found, restart Nginx. 如果未发现问题,请重新启动Nginx。
sudo systemctl restart nginx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.