14

I am dealing with the project deposition made on FastAPI to a remote ubuntu server. I'll try to run the project from terminal (using SSH connection) by the command

gunicorn -k uvicorn.workers.UvicornWorker main:app

The output is

gunicorn -k uvicorn.workers.UvicornWorker main:app
[2020-07-14 15:24:28 +0000] [23102] [INFO] Starting gunicorn 20.0.4
[2020-07-14 15:24:28 +0000] [23102] [INFO] Listening at: http://127.0.0.1:8000 (23102)
[2020-07-14 15:24:28 +0000] [23102] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2020-07-14 15:24:28 +0000] [23104] [INFO] Booting worker with pid: 23104
[2020-07-14 15:24:28 +0000] [23104] [INFO] Started server process [23104]
[2020-07-14 15:24:28 +0000] [23104] [INFO] Waiting for application startup.
[2020-07-14 15:24:28 +0000] [23104] [INFO] Application startup complete.

But I need the project to be available at the IP address of the server. If I try smth like

uvicorn main:app --host 66.226.247.55 --port 8000 

I get

INFO:     Started server process [23308]
INFO:     Waiting for application startup.
INFO:     Connected to database postgresql://recognition:********@localhost:5432/reco
INFO:     Application startup complete.
ERROR:    [Errno 99] error while attempting to bind on address ('66.226.247.55', 8000): cannot assign requested address
INFO:     Waiting for application shutdown.
INFO:     Disconnected from database postgresql://recognition:********@localhost:5432/reco
INFO:     Application shutdown complete.

Where 66.226.247.55 - external IP adress from google cloud platform instances How do I start a project so that it can be accessed via IP?

1
  • This problem should apply on virtual server such as Digital Ocean, Vultr and Linode. The proposed solution works well. Commented Jul 20, 2023 at 3:07

3 Answers 3

35

The --host should be the local address of your GCP server.

uvicorn main:app --host 0.0.0.0 --port 8000

and now access the application by http://66.226.247.55:8000

Note: You should open your 8000 port of GCP server.

Sign up to request clarification or add additional context in comments.

6 Comments

There's no mistake now. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) But I still can't get a response when I contact the IP address. Is there any other nuance?
Probably you didn't open your port 8000 of your GCP yet.
Allowed port 8000 using ufw sudo ufw allow 8000
I am not a pro in GCP or DevOps, But, you can try running something else in your GCP (say python HTTP server) and can check whether it is publically available or not.
Thank you, I'll try to do the same on digitalocean. Maybe there's a problem with GCP.
|
1

If you're using nginx server

create a file in /etc/nginx/sites-enabled/ create file touch fastapi_nginx copy code into file and adjust accordingly

server{
    listen 80;
    server_name "your public ip";
    location / {
        proxy_pass http://127.0.0.1:8000; #localhost
    }

}

This should reroute to your public ip

Comments

-2

You cannot launch your fast api app on your local to your remote server in GCP.

You must deploy your app to GCP. In other words you need to run that command on a remote server not your localhost.

1 Comment

Of course, I don't run the command from my local machine. My project is cloned to GCP and I run the command from the GC console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.