sphinx-doc / sphinx-autobuild

Watch a Sphinx directory and rebuild the documentation when a change is detected. Also includes a hot-reload web server.
MIT License
523 stars 75 forks source link

Auto-refresh webpage not working after reverse proxy via Nginx #150

Closed berlin2123 closed 3 months ago

berlin2123 commented 3 months ago

[ not bug of auto-build. but an issue on using it. ]

I am using Nginx as a front-end reverse proxy web-server, and sphinx-autobuild as back-end web-server.

back-end has make http://ip.addr:8000, works fine. front-end has make reverse proxy works, at last could open all pages fine by http://my.domain.name

However, the change of a page do not auto-refresh when opened by http://my.domain.name. Only update the page when manually refreshed. I have tested on open page by http://ip.addr:8000, directly to the sphinx-autobuild server, all page will auto-refresh after any changes.

here is the config file of nginx:

server {
    listen 80;                       
    server_name my_domain_name ;   

    location / {
        proxy_pass http://localhost:8000$request_uri;  
    }
}

So any way to make the auto-refresh enabled pass through the nginx reverse proxy ?

berlin2123 commented 3 months ago

Solved by adding three lines into nginx config file:

    location / {

        # enable hot-reloading or auto-refresh by the following three lines
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';

        proxy_pass http://localhost:8000$request_uri;  
    }

Seeing https://github.com/webpack/webpack-dev-server/issues/804 or https://www.wheelhouse.be/insights/setting-up-hot-reloading-behind-a-reverse-proxy