If you like video format, here is the youtube video.
install docker
sudo docker run -d -p 5000:5000 enriquecatala/fastapi-helloworld
make sure it's run properly by test it with
curl localhost:5000/docs
sudo apt update
sudo apt install nginx -y
sudo ufw app list
sudo ufw status
sudo ufw allow OpenSSH
sudo ufw allow "Nginx Full"
sudo ufw enable
sudo ufw status
Create a new Nginx configuration file:
sudo nano /etc/nginx/sites-available/reverse-proxy
Paste the following configuration into the file:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
}
}
basically we say to nginx that if there’s any request on port 80 please give it to localhost:5000
sudo rm /etc/nginx/sites-enabled/default
Create a symbolic link from the configuration file to the sites-enabled directory:
sudo ln -s /etc/nginx/sites-available/reverse-proxy /etc/nginx/sites-enabled/reverse-proxy
Check the syntax of your configuration:
sudo nginx -t
sudo nginx -s reload
now our sites is running, try to access http://your.ip.your.ip/
Once you have registered a domain name, you need to configure its DNS settings to point to your server's IP address. This is done by adding an "A" record to your domain's DNS settings. The "A" record maps your domain name to the IP address of your server. I recommend you to watch this youtube video about "How to Point a Domain Name to an IP Address (DNS A record example)"
After you have updated your domain's DNS settings, it can take some time for the changes to propagate throughout the internet
sudo nano /etc/nginx/sites-available/reverse-proxy
server {
listen 80;
server_name yourdomain.com;
return 301 http://www.yourcomain.com;
}
server {
listen 80;
server_name www.yourdomain.com;
location / {
proxy_pass http://localhost:5000;
}
}
sudo nginx -s reload
now our sites is running, try to access http://www.yourdomain.com/
sudo apt update
sudo apt install snapd
sudo snap install --classic certbot
Create a symbolic link for Certbot:
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot certonly --nginx
sudo nano /etc/nginx/sites-available/reverse-proxy
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/www.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.yourdomain.com/privkey.pem;
return 301 https://www.yourdomain.com;
}
server {
listen 443 ssl;
server_name www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/www.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.yourdomain.com/privkey.pem;
location / {
proxy_pass http://localhost:5000;
}
}
server {
listen 80;
server_name yourdomain.com;
return 301 https://www.yourdomain.com;
}
server {
listen 80;
server_name www.yourdomain.com;
return 301 https://www.yourdomain.com;
}
sudo nginx -s reload
now our sites is running, try to access https://www.yourdomain.com/