我有一个遗留的angular应用程序和一个新的react应用程序,我想通过nginx公开它们。
我有一个包含静态文件的产品nginx配置,但我试图让dev也能工作-使用热重载和webpack开发服务器。我已经让它正常工作了,但我意识到如果我能用/r/来限定react的范围,用/a/来限定angular应用程序的范围,那会更好。但是,使用下面的配置,每当我转到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;
}
发布于 2019-05-09 02:34:37
是的,有一个方法可以做到这一点:
location /static/ {
proxy_pass http:/172.17.0.2:3000/r/static/
...
}
查看the nginx.org docs for proxy_pass。
https://stackoverflow.com/questions/51955630
复制相似问题