Reactjs Nginx背后的React应用程序开发
我有一个旧的angular应用程序和一个新的react应用程序,我想通过nginx公开 我有一个生产nginx配置,其中包含静态文件,但我试图让dev也能正常工作——使用热重新加载和webpack dev服务器。我已经让它正常工作了,但是我意识到如果我可以用/r/和/a/定义react和angular应用程序的范围会更好。但是,使用下面的配置,每当我转到Reactjs Nginx背后的React应用程序开发,reactjs,nginx,create-react-app,Reactjs,Nginx,Create React App,我有一个旧的angular应用程序和一个新的react应用程序,我想通过nginx公开 我有一个生产nginx配置,其中包含静态文件,但我试图让dev也能正常工作——使用热重新加载和webpack dev服务器。我已经让它正常工作了,但是我意识到如果我可以用/r/和/a/定义react和angular应用程序的范围会更好。但是,使用下面的配置,每当我转到localhost/r/,bundle.js就位于/static/中。有没有办法让react应用程序的/static/变成/r/static/
localhost/r/
,bundle.js就位于/static/
中。有没有办法让react应用程序的/static/
变成/r/static/
有更好的方法吗
location /r {
proxy_pass http://172.17.0.2:3000;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /static/ {
proxy_pass http://172.17.0.2:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location /sockjs-node/ {
proxy_pass http://172.17.0.2:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
是的,有一种方法可以做到这一点:
location /static/ {
proxy_pass http:/172.17.0.2:3000/r/static/
...
}
退房。感谢@HappyCry展示了一种在nginx代理上热加载“npm启动”应用程序的方法。