Home > database >  nginx file configuration with static folder, in Flask Gunicorn Nginx application
nginx file configuration with static folder, in Flask Gunicorn Nginx application

Time:02-15

I have a Flask Gunicorn Nginx app, this is the settings for the sites-available file inside etc/nginx.

My problem is that the application does not load the images and the css styles, but the Flask logical theme, routes, login and others work.

The problem is with my static folder.

This is the configuration file:

server {
    listen 443 ssl;
    server_name dominio.com;

    ssl_certificate /etc/letsencrypt/live/dominio.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/dominio.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

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/suppliers.sock;
    }

    location /static/ {
        root /home/soporte/portal_providers/app_Portal;
        autoindex off;
    }
}

server {
    if ($host = dominio.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name dominio.com;
    return 404; # managed by Certbot
}

Archive blueprint Flask:

auth = Blueprint('auth', __name__,template_folder='templates', static_folder='static')

Link in the html with the image:

{% block logo %}
<img src="images/Logo--definitivo.jpg"  style="z-index: auto">
{% endblock %}

project structure enter image description here

CodePudding user response:

Try root instead of alias. The (working, deployed) nginx config for an app I'm working on does

location /static/ {
    root /home/pi/app;
    autoindex off;
}
  • Related