Streamlit behind nginx reverse proxy cannot resolve static js references

I am trying to deploy a streamlit app running on AWS on port 8501 behind an nginx reverse proxy on port 80. The URL the client would use to bring up my app would be http://${IP_ADDRESS}/clip-demo. My configuration is as follows, it goes inside the server section of /etc/ngnix/sites-enabled/default.

	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "upgrade";
	proxy_read_timeout 86400;

	location /clip-demo {
		rewrite ^/clip-demo(.*) /$1 break;
		proxy_pass http://127.0.0.1:8501;
	}

	location ^~ /clip-demo/static {
		proxy_pass http://127.0.0.1:8501/static/;
	}

	location ^~ /clip-demo/healthz {
		proxy_pass http://127.0.0.1:8501/healthz;
	}

	location ^~ /clip-demo/vendor {
		proxy_pass http://127.0.0.1:8501/vendor;
	}

	location ^~ /clip-demo/media {
		proxy_pass http://127.0.0.1:8501/media;
	}

	location /clip-demo/stream {
		proxy_pass  http://127.0.0.1:8501/stream;
		proxy_http_version 1.1; 
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Host $host;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_read_timeout 86400;
	}

I am able to bring up my streamlit app on my local browser by SSH port forwarding 8501 on the AWS machine to my local box, i.e. using ssh ... -L 8501:localhost:8501 and everything works fine.

However, when I try to bring this up through http://${IP_ADDRESS}/clip-demo, i.e. via the nginx reverse proxy, then I get a blank screen. Looking at the (Chrome) developer console, I see that streamlit application is failing on loading http://10.169.23.142/static/js/6.8dddd10a.chunk.js with net::ERR_ABORTED 404 NOT FOUND. This seems to be a Javascript file needed by streamlit.

BTW I have verified that nginx is working by doing http://10.169.23.142 and seeing the Nginx welcome page.

If I manually change the URL to http://10.169.23.142/clip-demo/static/js/6.8dddd10a.chunk.js it does resolve and bring back javascript text.

Since the URL is not something I can control through my application code, is there maybe a configuration parameter that would tell Streamlit to switch its calls to include the /clip-demo suffix?

Alternatively, is there a nginx configuration parameter I am missing? I have tried with both static/ and static in the static section, both give me identical behavior.

TIA for any help you can provide!

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.