0

Hello all I was hoping I could receive some guidance on this matter. I have a flask application that is setup on an ubuntu server. It uses ssh to create a tunnel to a Centos 7 Server that has it's mysql database. Upon running this application with python on the Ubuntu Server I'm able to perfectly login to my application and view data from database from domain ip. Now upon trying to run the application on nginx and uWSGI I can actually get to the login page from my domain name. But upon entering my credentials and trying to login, the page loads for around a minute and the I receive the 504 Connection Time Out Error

Would I be receiving this because my application is trying to reach out to another server while processing data from me. I'm not sure and nothing has been a help yet. Here are my files

server block

server {
    listen 80;
    server_name itinareport.tk www.itinareport.tk;

    location / {
        uwsgi_read_timeout 600;
        include uwsgi_params;
        uwsgi_pass unix:/home/pinchrep2/itinarep/itinarep.sock;
    }
}

ini file

[uwsgi]
module = wsgi:app

master = true
processes = 5

socket = itinarep.sock
chmod-socket = 660
vacuum = true

die-on-term=true

wsgi.py

from main import  app


if __name__ == "__main__":
    app.run()

service file

[Unit]
Description=uWSGI instance to serve itinarep
After=network.target

[Service]
User=pinchrep2
Group=www-data
WorkingDirectory=/home/pinchrep2/itinarep
Environment="PATH=/home/pinchrep2/itinarep/it_venv/bin"
ExecStart=/home/pinchrep2/itinarep/it_venv/bin/uwsgi --ini itinarep.ini

[Install]
WantedBy=multi-user.target

Here is where I ssh from main py file main.py

sshforward = SSHTunnelForwarder(
    ("public ip", 22),
   ssh_username = 'user',
   ssh_password = 'pass',
   remote_bind_address = ('127.0.0.1', 3306)
)
sshforward.start()
local_port = sshforward.local_bind_port

app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret_key'
app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://root@localhost:{local_port}/asteriskcdrdb"

if __name__ == "__main__":
    app.run(host='0.0.0.0')

Again I just need this to be deployed. Please point in the right direction configuration wise. I can get to application but as soon as logging in I receive this issue.

Andrew Venson
  • 203
  • 5
  • 14

1 Answers1

0

When your database connection url references "localhost", its really connecting via a unix socket.

You can connnect using a local_bind_address containing a unix socket adding ?unix_socket=/path/to/mysql.sock to the SQLALCHEMY_DATABASE_URI like this answer.

Seems connecting to a remote unix socket is waiting for this upstream issue to be implemented.

danblack
  • 12,130
  • 2
  • 22
  • 41