简体   繁体   中英

Nginx and flask static directory - CSS not linking correctly

This is my static directory:

  • /var/www/myapp/app/static/css
  • /var/www/myapp/app/static/js
  • /var/www/myapp/app/static/img

In my nginx config I have this:

location /static {
    alias /var/www/myapp/app/static;
    expires 30d;
    access_log off;
}

In my template I then use something like this:

<img height="60" src="{{url_for('static', filename='img/logo.jpg')}}"></img>

However, it doesn't render. When I view the source of my HTML page running under flask it renders it like this:

<img height="60" src="/static/img/logo.jpg">

What am I doing wrong here?

nginx_server.conf example

    root  /var/www/website/;

# make path root + location `name` = root + /static/ = real path
location /static/  {
    alias /var/www/website/static/;
    expires 30d;

}

Enjoy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM