Deploying notebook with nginx and voila on a different port than 80

Dear community,
I’m trying to deploy a jupyter-notebook on a private server using voila and nginx.

My configuration file for nginx is:

server {
    listen 1234;
    proxy_buffering off;
	      
     location / {
	    proxy_pass http://localhost:8869;

            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
	      }

	      
	      
    client_max_body_size 100M;
    error_log /var/log/nginx/error.log;
}

And I run the my jupyter notebook as:

voila ComputeEntropy_sub.ipynb --port=8869  --no-browser &

If I change the nginx configuration to listen at port 80 and connect to localhost, everything works. However if I change the listen port of nginx as in the example and connect to localhost:1234, the ipywidgets do not display in the notebook (only static markdown is rendered). Indeed, if I connect to localhost:8869 everything works.

The voila output does not show any error, while the nginx error log reports:

2021/08/20 18:12:54 [error] 25970#25970: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8869/", host: "localhost:1234"

How can I make it work correctly?

I found the solution.
I post it since it may be useful to other people.
Voila and Jupyter do not trust by default connection coming from a port different either from 80 or from the port they are running.
Thus if there is a port-forwarding configuration, to get everything running correctly one must tell voila (and jupyter) to trust all connections:

I added this in the command to start voila:

voila ComputeEntropy_sub.ipynb --port=8869  --no-browser --Voila.tornado_settings="{'allow_origin': '*'}" &
2 Likes