非默认静态位置的Flask nginx和静态文件问题

非默认静态位置的Flask nginx和静态文件问题,nginx,flask,gunicorn,Nginx,Flask,Gunicorn,我正在使用nginx(通过gunicorn)为flask应用程序提供静态文件 默认静态文件夹中的静态文件工作正常: <link rel="stylesheet" href="{{ url_for('static', filename='css/fa/font-awesome.min.css') }}" /> 在html中,我调用一个静态文件,因此: <link rel="stylesheet" href="{{ url_for('application_view.static

我正在使用nginx(通过gunicorn)为flask应用程序提供静态文件

默认静态文件夹中的静态文件工作正常:

<link rel="stylesheet" href="{{ url_for('static', filename='css/fa/font-awesome.min.css') }}" />
在html中,我调用一个静态文件,因此:

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

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

gunicorn
将使旧代码仍在运行,除非重新加载配置文件


您可以停止并重新启动
gunicorn
,或者向gunicorn进程发送HUP信号。

显示一些nginx配置和应用程序的更多详细信息。您在本地计算机上运行的是flask wsgi服务器还是gunicorn?你也可以发布你的nginx conf文件吗?@iurisilvio很抱歉我没有早点回来,我一直在忙于另一个项目。我已经添加了conf.d和nginx conf文件。我正在本地开发环境中运行flask打包服务器。@lesingerouge我正在本地开发环境中运行flask打包服务器。我正在重新加载所有配置文件,并在每次部署时停止并重新启动gunicorn。
upstream app_server_wsgiapp {
     server localhost:8000 fail_timeout=0;
}

server {
 listen 80;
 server_name www.mysitename.com;
 rewrite ^(.*) https://$server_name$1 permanent;
}


server {
  server_name           www.mysitename.com;
  listen                443 ssl;
  #other ssl config here
  access_log            /var/log/nginx/www.mysitename.com.access.log;
  error_log             /var/log/nginx/www.mysitename.com.error.log info;
  keepalive_timeout     5;
  # nginx serve up static files and never send to the WSGI server
  location /static {
    autoindex on;
    alias /pathtositeonserver/static;
  }

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_set_header Host $http_host;
       proxy_redirect off;
       if (!-f $request_filename) {
         proxy_pass http://app_server_wsgiapp;
         break;
    }
  }

  # this section allows Nginx to reverse proxy for websockets
  location /socket.io {
    proxy_pass http://app_server_wsgiapp/socket.io;
    proxy_redirect off;
    proxy_buffering off;

    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_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
  }
}
user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}