简体   繁体   中英

In Python + FastAPI, how to access a Gunicorn served website hosted in a VM on Oracle Cloud

I have a Python + FastAPI website, I use Gunicorn as the server. The website has been running successfully in local environment.

I have created a VM instance with Ubuntu 20.04 on Oracle Cloud and installed all needed Python packages.

I also followed this article to setup/enable Internet Access with port 5000 in Step 3 and Updated firewall settings in Step 4

I am not using virtual env.

Now I ssh into the VM and cd into the project root folder where the main.py is and ran this command:

gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --timeout 1200 --bind 0.0.0.0:5000

Here is how it looks like in the command line:

在此处输入图像描述

Here is how the subnet details look like:

在此处输入图像描述

Then when I tried to access the website by this link:

subnet05182336.vcn05182336.oraclevcn.com

My website is never showing up.

Server not Found

is displaying on the Tab.

Update 1

I found that I should use ip address( http://168.138.12.192/ ) to access my website.

I followed a new article to setup Nginx and now when accessing the IP, I can see the default Nginx website has been set up.

Here is my Ingress Rules:

在此处输入图像描述

How could I somehow make Nginx works with Gunicorn to see my Python website? Or maybe I don't even need Gunicorn any more after installed Nginx?

Could you please confirm from where are you trying to access the website? The DNS domain name that you have mentioned is only for internal within the OCI use, this cannot be accessed from outside. For that you need to configure Custom DNS zone.

Please try to access the website from a new terminal, connect to your Ubuntu VM with your SSH keys, and then in the command line enter curl localhost:5000. Or, you can connect your browser to the public IP address assigned to your VM: http://<xxxx>:5000.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM