Nginx和flask静态目录 - CSS未正确链接

时间:2022-11-22 19:16:33

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:

在我的nginx配置中,我有这个:

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:

但是,它不呈现。当我查看我在烧瓶下运行的HTML页面的来源时,它呈现如下:

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

What am I doing wrong here?

我在这做错了什么?

1 个解决方案

#1


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.

#1


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.