Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python nginx+;gunicorn&x2B;django/mezzanine不提供静态文件_Python_Django_Nginx_Gunicorn - Fatal编程技术网

Python nginx+;gunicorn&x2B;django/mezzanine不提供静态文件

Python nginx+;gunicorn&x2B;django/mezzanine不提供静态文件,python,django,nginx,gunicorn,Python,Django,Nginx,Gunicorn,我有一个夹层应用程序。我使用gunicorn作为web服务器,nginx作为反向代理。但是,不会提供静态文件(但是,它们是通过内置的django开发服务器提供的)。我已经运行了python manage.py 这是我的nginx.conf文件: worker_processes 1; events { worker_connections 1024; } http { sendfile on; gzip on; gzip_ht

我有一个夹层应用程序。我使用gunicorn作为web服务器,nginx作为反向代理。但是,不会提供静态文件(但是,它们是通过内置的django开发服务器提供的)。我已经运行了python manage.py

这是我的nginx.conf文件:

worker_processes 1;

events {

    worker_connections 1024;

}

http {

    sendfile on;

    gzip              on;
    gzip_http_version 1.0;
    gzip_proxied      any;
    gzip_min_length   500;
    gzip_disable      "MSIE [1-6]\.";
    gzip_types        text/plain text/xml text/css
                      text/comma-separated-values
                      text/javascript
                      application/x-javascript
                      application/atom+xml;

    # Configuration containing list of application servers
    upstream app_servers {

        server 127.0.0.1:8080;
        # server 127.0.0.1:8081;
        # ..
        # .

    }

    # Configuration for Nginx
    server {

        # Running port
        listen 80;

        # Settings to serve static files 
        location ^~ /static/  {

            # Example:
            # root /full/path/to/application/static/file/dir;
            root /root/myapp/myapp/static/;

        }

        # Serve a static file (ex. favico)
        # outside /static directory
        location = /favico.ico  {

            root /app/favico.ico;

        }

        # Proxy connections to the application servers
        # app_servers
        location / {

            proxy_pass         http://app_servers;
            proxy_redirect     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_set_header   X-Forwarded-Host $server_name;

        }
    }
}

如何为静态文件提供服务?

这似乎是在nginx中不正确地使用了
root
vs
alias
。假设在settings.py文件中有:

STATIC_URL = '/static/'
然后您需要一个如下所示的位置:

    location /static/  {
        # Example:
        # root /full/path/to/application/static/file/dir;
        root /root/myapp/myapp/;
        # - or -
        # alias /root/myapp/myapp/static/;
    }
用于:

定义指定位置的替换项。例如,使用以下配置

   location /i/ {
       alias /data/w3/images/;
   }
应“/i/top.gif”的请求,将发送文件/data/w3/images/top.gif。 ... 当位置与指令值的最后一部分匹配时:

 location /images/ {
   alias /data/w3/images/;
 }
最好改用root指令:

 location /images/ {
   root /data/w3;
 }

对不起,我没听懂。我应该用alias试试吗?您似乎建议我应该使用root,但我从未使用过alias,所以我有点困惑。请查看我的root指令和您的指令之间的差异。您可以使用root或alias,只需确保指向正确的目录即可。好的,我尝试了这两种方法(使用root指令删除“static”目录,并使用“alias”保留它)。两者都不起作用。静态资源返回403。您得到403?访问日志文件中有什么错误?“客户端IP”[18/Jan/2017:22:08:38+0000]“GET/static/css/bootstrap.css HTTP/1.1”403 178“站点IP”“用户代理”