How to deploy Streamlit on Windows IIS?

Has anyone successfully deployed a Streamlit application using Windows Server / IIS?

I’ve looked through every related post in this forum, and can only see one person who claims they have achieved it here: Simplest way to deploy a streamlit app in Windows server 2012 - Using Streamlit - Streamlit, but that method proved not to work for other users (my team included). Every other thread on the topic in this forum just runs dry!

Situation:

  • We are trying to host our new Streamlit app in a Windows VM using IIS (where we have a number of Flask/Dash apps already hosted)
  • We can run the app fine from within the VM (with streamlit run app.py)
  • We have followed the instructions listed in the above link (which is also linked to from the official ‘Deployment’ thread)
  • Visiting the address/port just returns “The Web server is configured to not list the contents of this directory.”, which means the app is not running and the server is looking for some default html to display when it gets no response

Any help would be immensely appreciated! :relaxed:

2 Likes

Also interested in this and the linked post also did not work - if you found a solution, could you post it here?

We managed to deploy in a Windows VM by avoiding IIS altogether and just using Task Scheduler. Perhaps a sub-optimal solution but worked a dream for our use case:

  • Create a batch file that simply contains streamlit run app.py (or perhaps also activates your virtualenv if you are using one) in the same directory as app.py
  • Open Task Scheduler, and create a new task
  • In the new task dialogue:
    • in General make sure to have ‘Run whether user is logged in or not’ checked
    • Create a new Trigger, we just used a daily trigger at 3am
    • Create a new Action. Set ‘Action’ to ‘Start a program’ and Browse for the batch file you created above
    • In Settings, at the bottom under ‘If the task is already running, then the following rule applies:’ select ‘Do not start a new instance’

What you end up with is an automated task that goes to start-up your app every night at 3am, unless its already running, in which case, keep the current one running!

We also specified which port we wanted to use etc. in the .streamlit/config.toml file. Plenty of docs around for that side of things.

Worked for us!

2 Likes

Hi @johnnybarrels ,

I tried using your solution but still didn’t work. I also had tried opening port 8501 and specified streamlit to run on that port.

Am I missing something ?

Hi, Thanks for the solution. What is the next step to create a public link for the app?

Hello,

I followed these steps and yet the application is not running. Is there a more systematic way to deploy it in windows server?

Did you ever find a solution? I’m trying to deploy put ended up having to run the conda environment but now I’m stuck trying to figure out a url redirect.

Hi

We have several streamlit instances running in a VM with IIS passing through to the streamlit instances based on the incomming url.

First of all to run the streamlit instance at startup, we are using a powershell script like:

Set-Location c:\python\streamlit
.\.venv\Scripts\Activate.ps1
streamlit  run .\app.py --server.headless true --browser.serverPort 80 --server.port 8511 --browser.serverAddress "streamlit_app"

This script is run at system startup by help of Task Scheduler.

  • General: Run whether user is logged on or not
  • Triggers: At startup
  • Action: Start a program:
    • program: powershell
    • Add arguments: -File C:\python\streamlit\run.ps1

Finally we need a IIS to forward to the streamlit instance, this is done by making a server Farm

  • Name: streamlit app
  • Add server:
    • Server addres: localhost
    • Advanced Settings → httpPort: 8511

Then Finish

And you need to make a URL Rewrite rule:

  • Match URL:
    • Requested URL: Matches the Pattern
    • Using: Regular Expressions
    • Pattern: (.*)
    • ignore case: True
  • Conditions:
    • Input: {HTTP_HOST}
    • Type: Matches the Pattern
    • ^streamlit_app$
  • Action
    • Action type: Route to Server Farm
    • Action Properties
      • Scheme: http://
      • Server farm: streamlit app
      • Path: /{R:0}
    • Stop processing of subsequent rules: True

For it to work you need to install the IIS module/feature “WebSocket Protocol”

Best regards Kristian

Hi,

Thanks for the solution. Can you please elaborate on the following? Steps to do the same?

Finally we need a IIS to forward to the streamlit instance, this is done by making a server Farm

* Name: streamlit app
* Add server:
  * Server addres: localhost
  * Advanced Settings → httpPort: 8511

Hi Arun

I don’t know what more there is to say. In IIS, under you server, right click on “Server Farms” and select “Create Server Farm”. Then put in the info as described and continue with making the rewrite rule.

You might need to install some extra stuff on your IIS web server, to get the server farms option, please checkout the Microsoft documentation: Configuring Step 1: Install IIS Web Farm Infrastructure | Microsoft Learn

This part I do not really remember as I did the initial setup 2 years ago.

Best regards Kristian

Thanks Kristian!

Here is what I am doing.

  1. I have run the below comment in powershell to run the app.
  2. streamlit run .\app.py --server.headless true --server.port 8501 --server.address "10.x.xx.xx" --browser.serverPort 80 --browser.serveraddress "stream_app.mydomain.com"
  3. The IP 10.x.xx.xx is one of the web servers on which I am running the app.
  4. Then I have a separate ARR server that routes all the .mydomain.com requests to my webserver.
  5. Created a site on ARR server with name Stream_App with binding Stream_App.mydomain.com

This procedure does not work for me. May be I am making some mistake.

but when I run the below command, it worked.


streamlit run .\app.py --server.headless true --server.port 8501 --server.address "10.x.xx.xx"

My aim is to run the app using a FQDN.

Any more suggestions on it.

Thanks !!

Hi Arun

I am not sure how you have set up your ARR Server, have you set it to point at 10.x.xx.xx and port 8501.

I have done this, by adding server farms, which forward to the ip and set the httpPort to the port of my streamlit instance in you case 8501
image
and


I am running everything on the same machine and only on a local network. So my serveradress is localhost.

I do hope this helps, as I have not tried to forward to another computer on the network.
/Kristian

Thanks Kristian! This helped me.