Flask + Python + Gunicorn: domain added in HestiaCP redirects to default page rather than my app

There are a few tutorials on how to setup a Python + Flask app, with Nginx and gunicorn, but could not find any tutorial or documentation on how to do it when HestiaCP is installed.

I am running HestiaCP at an Ubuntu 22.04 LTS server (VPS).

If is relevant… At the time Hestia was installed, I tried to install without Apache and without PHP, but the installer always modified to include PHP. Then I selected Apache without PHP, and it installed Apache and some PHP by itself. Install command line was created with https://gabizz.github.io/hestiacp-scriptline-generator/
ok, HestiaCP is installed.

After all set, with the app running at port 5000, if I try to access mypythonapp using my IP and port (eg.: 188.33.55.1:5000) I can see it is running as expected.

My domain dev.mydomain.com is set at Cloudflare DNS and points to my Ubuntu VPS server. My domain been added to my Ubuntu server with HestiaCP.

Nginx /etc/nginx/sites-available/myapp is set as following:

server {
    listen 443 ssl;
    listen 80;
    server_name dev.mydomain.com mydomain.com;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/myusername/myapp/myapp.sock;
                }
 }

The problem is that… if I try to access myapp with dev.mydomain.com or mydomain.com it always open a default page saying:

We´re working on it!

This site is currently under construction.

Please check back soon.

That default page is located at /home/myusername/web/dev.mydomain.com/public_html and seems was created by Hestia.

How to access myapp by using dev.mydomain.com (at port 80 and 443)?

http://unix:/home/myusername/myapp/myapp.sock;

Remove http://

Hi eris!

I removed http:// as you suggested, and restarted nginx, but unfortunately nothing changed.

Both, http://dev.mydomain.com and https://dev.mydomain.com are redirecting to that same “under construction” default page.

An additional relevant information…

If I stop apache2 service with sudo systemctl stop apache2, then the “under construction” default page is replaced by an error page:

Internal Server Error

Oops! Something went wrong.

The server encountered an internal error or misconfiguration and was unable to complete your request.
Error Code: 500

Check the error logs from apache to get more information on that 500 error.

Hi @maurice

Following your suggestion…

while acessing https://dev.mydomain.com with apache2 service stopped, at /var/log/apache2/domains/dev.mydomain.com.error.log I could see the Error 500 generate the following log:

2023/03/14 16:05:24 [error] 100557#100557: *474 connect() failed (111: Connection refused) while connecting to upstream, client: 189.4.99.199, server: dev.mydomain.com, request: "GET / HTTP/2.0", upstream: "https://88.111.55.111:8443/", host: "dev.mydomain.com"

And as an additional information, that are the services listening the ports:

root@vmi1234567:~# lsof -i :80
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx    20262     root   11u  IPv4  55396      0t0  TCP vmi1234567.contaboserver.net:http (LISTEN)
nginx   100557 www-data   11u  IPv4  55396      0t0  TCP vmi1234567.contaboserver.net:http (LISTEN)
nginx   100559 www-data   11u  IPv4  55396      0t0  TCP vmi1234567.contaboserver.net:http (LISTEN)
nginx   100560 www-data   11u  IPv4  55396      0t0  TCP vmi1234567.contaboserver.net:http (LISTEN)
nginx   100561 www-data   11u  IPv4  55396      0t0  TCP vmi1234567.contaboserver.net:http (LISTEN)

root@vmi1234567:~# lsof -i :443
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx    20262     root   12u  IPv4  55397      0t0  TCP vmi1234567.contaboserver.net:https (LISTEN)
nginx   100557 www-data   12u  IPv4  55397      0t0  TCP vmi1234567.contaboserver.net:https (LISTEN)
nginx   100559 www-data   12u  IPv4  55397      0t0  TCP vmi1234567.contaboserver.net:https (LISTEN)
nginx   100560 www-data   12u  IPv4  55397      0t0  TCP vmi1234567.contaboserver.net:https (LISTEN)
nginx   100561 www-data   12u  IPv4  55397      0t0  TCP vmi1234567.contaboserver.net:https (LISTEN)


(*) vmi1234567: modified to sequential numbers

My VPS provider is Contabo.

And after restart the apache2:

root@vmi1234567:~# sudo systemctl start apache2
root@vmi1234567:~# lsof -i :8080
COMMAND    PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
apache2 129536     root    5u  IPv4 319261      0t0  TCP vmi1234567.contaboserver.net:http-alt (LISTEN)
apache2 129537 www-data    5u  IPv4 319261      0t0  TCP vmi1234567.contaboserver.net:http-alt (LISTEN)
apache2 129538 www-data    5u  IPv4 319261      0t0  TCP vmi1234567.contaboserver.net:http-alt (LISTEN)
apache2 129539 www-data    5u  IPv4 319261      0t0  TCP vmi1234567.contaboserver.net:http-alt (LISTEN)
apache2 129540 www-data    5u  IPv4 319261      0t0  TCP vmi1234567.contaboserver.net:http-alt (LISTEN)
apache2 129541 www-data    5u  IPv4 319261      0t0  TCP vmi1234567.contaboserver.net:http-alt (LISTEN)
apache2 129542 www-data    5u  IPv4 319261      0t0  TCP vmi1234567.contaboserver.net:http-alt (LISTEN)

myapp runs as a service /etc/systemd/system/myapp.service with the following setting:

[Unit]
Description=Gunicorn instance to serve myapp
After=network.target

[Service]
User=myusername
Group=www-data
WorkingDirectory=/home/myusername/myapp
Environment="PATH=/home/myusername/myapp/venv/bin"
ExecStart=/home/myusername/myapp/venv/bin/gunicorn --workers 3 --bind unix:myapp.sock -m 007 app:app

[Install]
WantedBy=multi-user.target