简体   繁体   English

nginx 反向代理后的 create-react-app 代码更改未在浏览器中重新加载

[英]create-react-app code changes behind nginx reverse proxy not reloading in browser

Ive installed a new CRA template and Im unable to see file changes reflect in the browser.我安装了新的 CRA 模板,但无法在浏览器中看到文件更改。 Im reverse proxying React app through nginx using unmodfied CRA installation (unmodified apart from setting.env VAR PORT corresponding to standard nginx websocket proxy config).我使用未修改的 CRA 安装通过 nginx 反向代理 React 应用程序(除了 setting.env VAR PORT 对应于标准 nginx websocket 代理配置之外未修改)。 Still I see persistent browser error:我仍然看到持续的浏览器错误:

webpackHotDevClient.js:60 WebSocket connection to 'wss://react.syntapse.co.uk/sockjs-node' failed: Error during WebSocket handshake: Unexpected response code: 301

.env file .env 文件

PORT=3121

nginx configuration nginx配置

server {
    listen 80;
    server_name react.syntapse.co.uk;

    location /sockjs-node/ {
        proxy_pass http://0.0.0.0:3121/sockjs-node/;
        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 / {
        proxy_pass http://0.0.0.0:3121/;
        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;
    }
}

I haven;t taken any specific steps to enable HMR or any form of hot reloading just expecting code changes to update in the browser.我没有采取任何具体步骤来启用 HMR 或任何形式的热重载,只是希望代码更改能够在浏览器中更新。 I'm trying out different platforms and ive got near identical nginx config for default angular and vue apps which just work with HMR out the box so I guess React config needs tweaking to work with through proxy but the documentation is a bit sparse.我正在尝试不同的平台,我得到了几乎相同的 nginx 默认配置 angular 和开箱即用的 Vue 应用程序,所以我猜 React 配置需要调整才能通过代理工作,但文档有点稀疏。

Any help or insights into using React with nginx reverse proxy are much appreciated.非常感谢将 React 与 nginx 反向代理一起使用的任何帮助或见解。

Thanks谢谢

Answer in plain sight the whole time.始终在众目睽睽下回答。 drop the end slash.删除结束斜杠。

location /sockjs-node {
    proxy_pass http://0.0.0.0:3121/sockjs-node;
    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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM