Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 5956

Failling to run a waitress (flask) webserver with NGINX

$
0
0

I have been trying to run a flask waitress server on ubuntu with NGINX.

This is my current NGINX config:

server {    listen 80;    server_name mydomain.com www.mydomain.com;    client_max_body_size 64M;  # Adjust the size as needed    large_client_header_buffers 4 32k;    location / {        proxy_pass http://127.0.0.1:80;        proxy_set_header Host $host;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        proxy_set_header X-Forwarded-Proto $scheme;    }    listen 443 ssl; # managed by Certbot    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot}

And my waitress application below:

    def start(self):        # Start the database instance        self.db.start()        # Set the DEBUG flag to False in production mode        self.application.app.config["DEBUG"] = False        # Store a reference to the application instance        app_instance = self.application.app        # If we are in production mode        if self.prod:            # Set the host to "0.0.0.0" (all network interfaces) and the port to 8080            url = "127.0.0.1:80"            # Print the URL that the application is running on            print(f"Running PROD: http://{url}")            # Start the application with Waitress, a production-ready WSGI server            # The number of threads is set to 40            self.register()            waitress.serve(app_instance, listen=url, threads=10)        else:            # If we are in development mode            print("Running DEV")            # Run the application with its built-in development server            # The host is set to "0.0.0.0" (all network interfaces), the port is 8080,            # and debug mode is enabled            self.register()            self.application.run(host="127.0.0.1", port=80, debug=True,url_scheme='https', threaded=True)

What I am having trouble with, the webpage previously returned error 400 header size issues hence I specified a large_client_header_buffers object, and now it seems to return error 500 continuously.

And the most recent logs from nginx are as follows:

2024/06/21 20:15:03 [alert] 2935#2935: *48088 socket() failed (24: Too many open files) while connecting to upstream, client: 127.0.0.1, server: mydomain.com, request: "GET / HTTP/1.0", upstream: "http://127.0.0.1:80/", host: "mydomain.com"

I have got the flask app setup to run on crontab when the system boots, and NGINX also starts on boot.

Any help at all would be appreciated!


Viewing all articles
Browse latest Browse all 5956

Trending Articles