【发布时间】:2019-05-09 02:34:36
【问题描述】:
我有一个旧的 Angular 应用程序和一个新的 React 应用程序,我想通过 nginx 公开。
我有一个包含静态文件的生产 nginx 配置,但我试图让 dev 也能正常工作 - 使用热重载和 webpack 开发服务器。我有这个工作,但我意识到如果我可以使用 /r/ 和 /a/ 来确定反应范围会更好。但是,使用下面的配置,每当我转到 localhost/r/ 时,bundle.js 都会位于 /static/ 中。有没有办法将 /static/ 设置为 /r/static/ 用于 react 应用?
有更好的方法吗?
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;
}
【问题讨论】:
-
感谢 @HappyCry 展示了一种在 nginx 代理上热重载“npm start”应用程序的方法。
标签: reactjs nginx create-react-app