# Deploy with Nginx and HTTPS

**URL:** <https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513>\
**Category:** Deployment\
**Tags:** nginx, https\
**Created:** [September 26, 2021, 3:13am UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513 "2021-09-26T03:13:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![istjohn](https://avatars.discourse-cdn.com/v4/letter/i/ee59a6/32.png) [@istjohn](https://discuss.streamlit.io/u/istjohn)\
**Post date:** [September 26, 2021, 3:13am UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513/1 "2021-09-26T03:13:11Z")

</div>

It took me a couple days to figure out how to get Streamlit running on my Ubuntu server behind an Nginx reverse proxy with HTTPS, so I wanted to share how I did it and maybe I can save someone else some headache.

This is what my Nginx configuration file looks like. It’s located at `/etc/nginx/sites-available/mydomain.com` and linked from `/etc/nginx/sites-enabled/mydomain.com`.

```auto
server {
        server_name mydomain.com;
        root /var/www/mydomain.com/html;

        location / {
                proxy_pass http://127.0.0.1:8501;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_redirect off;
                proxy_http_version 1.1;

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

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/calle.xwx.mx/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/calle.xwx.mx/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server { # managed by Certbot
    if ($host = mydomain.com) { # managed by Certbot
        return 301 https://$host$request_uri; # managed by Certbot
    } # managed by Certbot

        listen 80; # managed by Certbot
        listen [::]:80; # managed by Certbot

        server_name calle.xwx.mx; # managed by Certbot
    return 404; # managed by Certbot
} # managed by Certbot

```

Note that the lines with the “Certbot” comments were generated for me by Certbot. [Here’s a great Digital Ocean guide on that.](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04)

Then, I created the following file at `~/.streamlit/config.toml`:

```auto
[browser]
serverPort = 443
serverAddress = "mydomain.com"
gatherUsageStats = false

```

---

<div class="post-metadata">

**Author:** ![vulum](https://avatars.discourse-cdn.com/v4/letter/v/b77776/32.png) [@vulum](https://discuss.streamlit.io/u/vulum)\
**Post date:** [October 1, 2021, 1:22am UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513/2 "2021-10-01T01:22:39Z")

</div>

And does your streamlit server boot on systems boot? or you have to manually start it with something like “streamlit run your\_app.py”??

---

<div class="post-metadata">

**Author:** ![Ruben\_S](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/ruben_s/32/3642_2.png) [@Ruben\_S](https://discuss.streamlit.io/u/Ruben_S)\
**Post date:** [November 11, 2021, 12:33pm UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513/3 "2021-11-11T12:33:13Z")

</div>

This seems close to what I need. Thanks for sharing. I am trying to [http://localhost:8501](http://localhost:8501) to httpS//localhost:8501. Could you help me, what do I need to change?

---

<div class="post-metadata">

**Author:** ![cconsta1](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/cconsta1/32/74935_2.png) [@cconsta1](https://discuss.streamlit.io/u/cconsta1)\
**Post date:** [November 28, 2021, 3:55pm UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513/4 "2021-11-28T15:55:46Z")

</div>

Hi, I’m working on a similar problem, I have two Docker containers, one which runs nginx and one running streamlit. I tried to do the reverse proxy approach I read here and there with no success. My app is indeed running but only on HTTP. Where should I put this configuration file you shared. And thanks for sharing btw!

---

<div class="post-metadata">

**Author:** ![Gourab\_Hazra](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/gourab_hazra/32/16985_2.png) [@Gourab\_Hazra](https://discuss.streamlit.io/u/Gourab_Hazra)\
**Post date:** [July 22, 2022, 10:25am UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513/5 "2022-07-22T10:25:14Z")

</div>

This does not work i get an error saying

400 Bad Request

## The plain HTTP request was sent to HTTPS port

nginx/1.18.0 (Ubuntu)

---

<div class="post-metadata">

**Author:** ![c00lcoder](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/c00lcoder/32/20677_2.png) [@c00lcoder](https://discuss.streamlit.io/u/c00lcoder)\
**Post date:** [September 25, 2022, 12:50am UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513/6 "2022-09-25T00:50:00Z")

</div>

Hey Streamlit Community - I’ve followed along multiple examples but still haven’t been able to create the secure connection. Has anyone figured out a streamlined way to achieve this secure HTTPS connection yet? Has anyone tried 3rd party services like localtunnel, ngrok, etc…?

EC2 - Ubuntu - Nginx

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/streamlit/original/3X/c/f/cf4c2ee0d938358f82448c5fe4b9c3c91d7ce19c.svg) [@system](https://discuss.streamlit.io/u/system)\
**Post date:** [January 3, 2024, 7:11pm UTC](https://discuss.streamlit.io/t/deploy-with-nginx-and-https/17513/8 "2024-01-03T19:11:46Z")

</div>

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