Running fastapi app using uvicorn on ubuntu server - gunicorn

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?

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.

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

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.

Related

DBGp proxy error Handler response error: Error reading command: Don't understand command '[507]'

Remote debugging using Xdebug DBGp proxy and PhpStorm:
Ubuntu 22.10
PHP 8.1
Xdebug v3.1.2
Xdebug DBGp proxy (0.4.2-dev)
./dbgpProxy
Xdebug DBGp proxy (0.4.2-dev)
Copyright 2020 by Derick Rethans
2023-02-13 07:16:48.394 [warn] [SSL] The 'certs/fullchain.pem' file could not be found, not enabling SSL listeners
2023-02-13 07:16:48.394 [info] [dbgpProxy] Proxy started
2023-02-13 07:16:48.395 [info] [server] Started server server on 127.0.0.1:9003
2023-02-13 07:16:48.395 [info] [server] Started client server on 127.0.0.1:9001
Xdebug settings:
zend_extension=xdebug.so
xdebug.mode=debug
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
xdebug.log=/tmp/xdebug.log
SSH settings:
RemoteForward 9001 localhost:9001
LocalForward 9001 localhost:9001
Tools -> DBGp proxy -> Register IDE
2023-02-13 07:17:08.768 [info] [server] Start new client connection from 127.0.0.1:33682
2023-02-13 07:17:08.839 [info] [proxyinit] [POLYANIN] Added connection for IDE Key 'POLYANIN': 127.0.0.1:9001
2023-02-13 07:17:08.840 [info] [server] Closing client connection from 127.0.0.1:33682
The error:
2023-02-13 07:28:18.141 [info] [proxy-client] [POLYANIN] Found connection for IDE Key 'POLYANIN': 127.0.0.1:9001
2023-02-13 07:28:18.141 [info] [proxy-client] [POLYANIN] Connecting to 127.0.0.1:9001
2023-02-13 07:28:18.142 [info] [proxy-client] [POLYANIN] IDE connected
2023-02-13 07:28:18.142 [info] [server] Start new client connection from 127.0.0.1:33694
2023-02-13 07:28:18.142 [info] [proxy-client] [POLYANIN] Init forwarded, start pipe
2023-02-13 07:28:18.142 [warn] [server] Handler response error: Error reading command: Don't understand command '[507]'
2023-02-13 07:28:18.142 [info] [server] Closing client connection from 127.0.0.1:33694
2023-02-13 07:28:18.192 [info] [proxy-client] [POLYANIN] IDE closed connection
I put a breakpoint and refresh the page.
You cannot use the DBGp proxy this way, as it always sends the debug data to the host where the IDE registration with the key came from.
Since you are using a tunnel, it always comes from 127.0.0.1; this is why you get Found connection for IDE Key 'POLYANIN': 127.0.0.1:9001, and this is why you get the error message - the proxy tries to send the debug data to itself instead of PhpStorm.
There is an extremely ugly workaround - you can modify the proxy code so that it uses the IDE key as a port number to connect to:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010264920-xdebug-multiple-developers-php-storm-dbgpproxy

Configure wiki.js(open source) on AWS EC2 instance

I've deployed wiki.js on AWS EC2 instance using docker. With installation Command as follows :
docker run -d -p 8080:3000 --name wiki --restart unless-stopped -e "DB_TYPE=mysql" -e "DB_HOST=172.0.0.1" -e "DB_PORT=3306" -e "DB_USER=wikijs" -e "DB_PASS=wikijsrocks" -e "DB_NAME=wiki" requarks/wiki:2
I've referred wiki.js installation .
DB container and wiki containers are running in the same instance, When I check the above-created container logs, it shows the below output.
Loading configuration from /wiki/config.yml... OK
2021-07-21T16:13:45.924Z [MASTER] info: =======================================
2021-07-21T16:13:45.926Z [MASTER] info: = Wiki.js 2.5.201 =====================
2021-07-21T16:13:45.926Z [MASTER] info: =======================================
2021-07-21T16:13:45.927Z [MASTER] info: Initializing...
2021-07-21T16:13:47.149Z [MASTER] info: Using database driver mysql2 for mysql [ OK ]
2021-07-21T16:13:47.153Z [MASTER] info: Connecting to database...
2021-07-21T16:13:47.189Z [MASTER] info: Database Connection Successful [ OK ]
2021-07-21T16:13:47.237Z [MASTER] warn: DB Configuration is empty or incomplete. Switching to Setup mode...
2021-07-21T16:13:47.238Z [MASTER] info: Starting setup wizard...
2021-07-21T16:13:47.477Z [MASTER] info: Starting HTTP server on port 3000...
2021-07-21T16:13:47.478Z [MASTER] info: HTTP Server on port: [ 3000 ]
2021-07-21T16:13:47.482Z [MASTER] info: HTTP Server: [ RUNNING ]
2021-07-21T16:13:47.482Z [MASTER] info: πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»πŸ”»
2021-07-21T16:13:47.483Z [MASTER] info:
2021-07-21T16:13:47.483Z [MASTER] info: Browse to http://YOUR-SERVER-IP:3000/ to complete setup!
2021-07-21T16:13:47.483Z [MASTER] info:
2021-07-21T16:13:47.483Z [MASTER] info: πŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”ΊπŸ”Ί
But when I run container IP + port into the browser it shows This site can't be reached
I've already opened ports 80, 443, and 3000 inside the security group attached with this instance. Unable to figure out the reason, why it's not loading wiki.js on the running URL.
It works deliberately in a local docker container, but not in a remote container. Can anyone please help me with this, any help would be appreciated.Thanks in advance.
Same log output but with Postgre in the version I got. I managed to get it working by just running docker start wiki, following the installation process in Wiki.js website.
Have you set the inbound rules of the instance to allow you access over HTTP (not HTTPS)? If yes, you access the instance by just browsing its IP address (No port either as suggested). This is consistent with the local container I set up too.
Make sure the instance has an inbound rule/security group that supports HTTP requests (IPv4 version, TCP protocol, Port range of 80 and the appropriate Source depending on your case).

IPFS private network connect timeout

I have 2 home PCs with windows 10. I want to create test ipfs private network between 2 nodes.
I downloaded go-ipfs.
ipfs version 0.6.0
I executed
ipfs init
ipfs bootstrap rm --all
I made swarm.key and added node to config.
ipfs bootstrap add /ip4/62.122.132.55/tcp/4001/ipfs/QmYY9U3JFuMykjRjKd1jg6aPCmcf2UYpbaS8fHpwkAVvia
I checked if port 4001 is listening.
TCP [::]:4001 [::]:0 LISTENING
The same I made on the second node.
I started nodes
ipfs daemon
The result was
Initializing daemon...
go-ipfs version: 0.6.0
Repo version: 10
System version: amd64/windows
Golang version: go1.14.4
Swarm is limited to private network of peers with the swarm key
Swarm key fingerprint: 4c11fea5d8ab67ccf08b22a4ee220db3
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.1.102/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.1.102/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready
On second node I tried execute
c:\ipfs>ipfs swarm connect /ip4/62.122.132.55/tcp/4001/ipfs/QmYY9U3JFuMykjRjKd1jg6aPCmcf2UYpbaS8fHpwkAVvia
Error: connect QmYY9U3JFuMykjRjKd1jg6aPCmcf2UYpbaS8fHpwkAVvia failure: \
failed to dial QmYY9U3JFuMykjRjKd1jg6aPCmcf2UYpbaS8fHpwkAVvia: all dials failed
* [/ip4/62.122.132.55/tcp/4001] dial tcp4 0.0.0.0:4001->62.122.132.55:4001: i/o timeout
c:\ipfs>
After some time daemon showed
Daemon is ready
2020-07-19T08:43:50.560+0300 [31mERROR[0m reprovider.simple simple/reprovide.go:108 \
failed to reprovide: failed to find any peer in table
What I missed?
can you run the following commands?
ipfs id
https://docs.ipfs.io/reference/cli/#ipfs-id
ipfs swarm peers
https://docs.ipfs.io/reference/cli/#ipfs-swarm-peers
ipfs boostrap list
https://docs.ipfs.io/reference/cli/#ipfs-bootstrap

How to know where ejabberd is config

I am working on old project where ejabberd is used. In laravel env file this information is written
JABBER_SERVER=localhost
JABBER_ENV=dev
RPC_SERVER= http://xx.xx.xx.xxx:4560/RPC2
JABBER_HOST=localhost
when i try to find the ejabberd service on my ubuntu server i couldn't.I don't have any idea how i can find ejabberd information because i am getting an error.
2019-12-26 07:54:27.338 [info] <0.23787.5>#ejabberd_c2s:process_terminated:264 (tcp|<0.23786.5>) Closing c2s session for prod6067#localhost/121590970668513998469410: Connection failed: connection closed
2019-12-26 07:54:30.577 [info] <0.339.0>#ejabberd_listener:accept:300 (<0.23789.5>) Accepted connection 115.186.58.62:58101 -> 172.31.42.93:5222
2019-12-26 07:54:31.390 [info] <0.23790.5>#ejabberd_c2s:handle_auth_success:423 (tcp|<0.23789.5>) Accepted c2s SCRAM-SHA-1 authentication for prod6067#localhost by mnesia backend from
2019-12-26 07:54:32.166 [info] <0.23790.5>#ejabberd_c2s:bind:394 (tcp|<0.23789.5>) Opened c2s session for prod6067#localhost/151108589900049164879426
If you can run the ejabberdctl shell script, then it will show many information about where ejabberd is installed:
$ ejabberdctl
...
Optional parameters when starting an ejabberd node:
--config-dir dir Config ejabberd: /etc/ejabberd
--config file Config ejabberd: /etc/ejabberd/ejabberd.yml
--ctl-config file Config ejabberdctl: /etc/ejabberd/ejabberdctl.cfg
--logs dir Directory for logs: /usr/local/var/log/ejabberd
--spool dir Database spool dir: /usr/local/var/lib/ejabberd
--node nodename ejabberd node name: ejabberd#localhost

mysql and gunicorn open connections at the same port

SOME BACKGROUND:
I have created a django app and I am at the point where I want to deploy it. I have looked at multiple options including wsgi but since the new mac os update came about, I can not install mod_wsgi because I do not have apxs or apxs2 on my computer, (Some discussion on web about rights to write in files, If you know more and would like to explain, please do.)
However, I looked into other options to try to deploy the app and I want to use Heroku. I have followed the dev guide for Django deployment until I reached the part where I test using "heroku local web".
THE ISSUE
The problem stems from here because the local mysql server uses the same port that the gunicorn is also trying to use. I have found similar posts on stackoverflow about 'connections in use' but none have shown how to change ports for gunicorn. I have found some open ports available on my localhost but everytime I try to change the mysql ports to those, the connection times out. Therefore, I would like to know how to change the port the Gunicorn connects to so it does not try to connect to the same default port as the mysql which is 3306.
I was serving the django project with the server it came with and the database I am using is mysql for local production. I am trying to connect locally with gunicorn and Heroku now because I feel that if this goes right locally it will probably go right when I attempt to put the project online.
ERROR GIVEN
10:38:52 PM web.1 | [2017-01-08 22:38:52 -0500] [83200] [ERROR] Connection in use: ('0.0.0.0', 3306)
10:38:52 PM web.1 | [2017-01-08 22:38:52 -0500] [83200] [ERROR] Retrying in 1 second.
10:38:53 PM web.1 | [2017-01-08 22:38:53 -0500] [83200] [ERROR] Connection in use: ('0.0.0.0', 3306)
10:38:53 PM web.1 | [2017-01-08 22:38:53 -0500] [83200] [ERROR] Retrying in 1 second.
10:38:54 PM web.1 | [2017-01-08 22:38:54 -0500] [83200] [ERROR] Connection in use: ('0.0.0.0', 3306)
10:38:54 PM web.1 | [2017-01-08 22:38:54 -0500] [83200] [ERROR] Retrying
in 1 second.
MY PROFILE
web: gunicorn project_name.wsgi.application --log-file -
The gunicorn connects when I stop the mysql server, but I get an exception since the project can not connect to the databases.
--Thank you
You can specify the port for Gunicorn as follows -
gunicorn --bind 127.0.0.1:8000
So basically the complete command would be
gunicorn --bind 127.0.0.1:8000 myproject.wsgi:application
You can change 8000 to any of your desired port number.
To install mod_wsgi on MacOS X see:
https://pypi.python.org/pypi/mod_wsgi
All you need to do is pip install mod_wsgi.
You can then use mod_wsgi-express on the command line to run it on an unprivileged port, with all configuration done for you.
Or, you can integrate it with existing Apache installation and manually configure it yourself by running mod_wsgi-express module-config and taking what it outputs and add it to the main Apache configuration for the system. Then add you specific WSGI application configuration to the Apache configuration file as well.