Nginx 404s Flask / Docker中的所有静态资产

时间:2018-07-16 01:20:38

标签: docker nginx flask

我所有的静态资产都是404ing。我不知道为什么,因为我的Nginx正确地路由了它们,当我将bash放入docker容器时,我可以看到资产在那里。

这是我的Nginx配置:

# the upstream component nginx needs to connect to
upstream flask {
    server unix:///tmp/uwsgi.sock;
}

# configuration of the server
server {
    # the port your site will be served on
    listen 8080 default_server;
    server_name _;

    # the domain name it will serve for
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /usr/src/app/app/myApp/static; # your project's static files - amend as required
        autoindex on;
    }

    location / {
        uwsgi_pass  flask;
        include  uwsgi_params;
    }
}

这是模板中链接断开的示例:

<link rel="stylesheet" href="{{ url_for('static', filename='dist/css/main.css') }}">

在此路径上会得到404,这看起来是正确的:

  

http://localhost:9090/static/dist/css/main.css

我不确定您还需要其他哪些信息来诊断此问题,其他所有似乎都正常。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

问题在server_name _;中。删除它或设置server_name localhostserver_name ~.