Running Streamlit on IIS, but getting error 502 - Bad Gateway

Hello,

I am trying to deploy my multipage streamlit application through IIS but I am getting error 502 - Bad Gateway.

I followed the instructions through https://discuss.streamlit.io/t/how-to-host-streamlit-app-in-windows-iis/62720 and the links related using ARR and url rewrite for a reverse proxy, but it still doesn’t work. I also attempted to create smaller codes to debug, but I still get the same error.

Has anyone encountered this problem and knows how to navigate it?

Thank you in advance for any tips on how to deal with this situation!

Hey there, thanks for reaching out to the Streamlit community! A 502 Bad Gateway error when deploying Streamlit behind IIS with ARR and URL Rewrite is a common issue, usually related to WebSocket misconfiguration or the reverse proxy not forwarding requests correctly. Streamlit relies on WebSockets for client-server communication, and IIS needs to be set up to support this.

Key troubleshooting steps:

  • Ensure the IIS WebSocket Protocol feature is installed and enabled.
  • Double-check your URL Rewrite and ARR rules to make sure they forward both HTTP and WebSocket traffic to the correct Streamlit port.
  • Many users report that the 502 error is resolved by disabling CORS and WebSocket compression in Streamlit’s config. Add these lines to your .streamlit/config.toml:
[server]
enableCORS = false
enableWebsocketCompression = false
  • Make sure the Streamlit app is running and accessible on the target port (e.g., http://localhost:8501) before proxying.
  • If you see a blank page or infinite loading, it’s often due to the WebSocket connection not being established—check browser console logs for WebSocket errors.

For more details and step-by-step community solutions, see this IIS deployment thread, this reverse proxy troubleshooting post, and official Streamlit docs on remote deployment issues.

If you’re still stuck, please share your IIS rewrite rules, ARR config, and any relevant Streamlit logs or browser errors. The community is always happy to help debug further!

Sources: