A
A
arsfilinov2021-08-13 18:18:41
Nginx
arsfilinov, 2021-08-13 18:18:41

How to bind uvicorn to a domain on the server?

61168db68f707734644195.pngHello, how to install yuvicorn on your domain? I run it on a web server from reg ru, but it runs on a local host reg ru with a domain in the form of an IP address, how can I make it work on my domain?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2021-08-13
@deepblack

Set up nginx to proxy requests to uvicorn, specify the domain there and at the same time you can attach a certificate from Let's Encrypt after you master the initial setup

spoiler

http {
  server {
    listen 80;
    client_max_body_size 4G;

    server_name example.com;

    location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_redirect off;
      proxy_buffering off;
      proxy_pass http://uvicorn;
    }

    location /static {
      # path for static files
      root /path/to/app/static;
    }
  }

  map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
  }

  upstream uvicorn {
    server 127.0.0.1:8000;
  }

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question