【发布时间】:2023-04-08 02:09:01
【问题描述】:
我正在尝试在远程 Ubuntu 服务器上创建一个 ReactJS 应用程序。为了在浏览器中测试它,我使用了 NGinx 反向代理功能。
server {
listen 80;
server_name mentalg.com;
location / {
proxy_pass http://172.31.23.249:5000;
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 /client/ {
proxy_pass http://172.31.23.249: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;
}
}
5000 端口用于 REST /api 端点,在这里都很好。
但是开发反应服务器运行的 3000 端口会产生问题。
该站点根据需要在http://mentalg.com/client 处打开,但在index.html 内有一个用于执行脚本文件的url
static/js/bundle.js 文件。该文件通常由 React 开发服务器提供,但 NGinx 不会看到它。
static/js/bundle.js 的 url 是由create-react-app 开发服务器动态生成的,无法控制。
如何进一步修改 nginx 代理以正确服务器来自 static 文件夹的文件?
【问题讨论】:
-
也许可以通过重写来解决它?我有同样的问题,但我不确定如何。
标签: reactjs create-react-app nginx-reverse-proxy