Nginx gunicorn重定向不工作和空文件

时间:2017-02-08 15:09:57

标签: django nginx gunicorn

我正在设置一个带有nginx和gunicorn的生产服务器。我使用了gunicorn示例页面中的nginx.conf并对其进行了修改:

worker_processes 1;

user mypolls webapps;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
pid /var/run/nginx.pid;
error_log /webapps/mypolls/logs/nginx.error.log;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # set to 'on' if nginx worker_processes > 1
  # 'use epoll;' to enable for Linux 2.6+
  # 'use kqueue;' to enable for FreeBSD, OSX
}

http {
  # fallback in case we can't determine a type
  default_type application/octet-stream;
  access_log /webapps/mypolls/logs/nginx.access.log combined;
  sendfile on;

upstream app_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response

    # for UNIX domain socket setups
    server unix:/webapps/mypolls/run/gunicorn.sock fail_timeout=0;

    # for a TCP configuration
    # server 192.168.0.7:8000 fail_timeout=0;
  }

  server {
    # if no Host match, close the connection to prevent host spoofing
    listen 80 default_server;
    return 444;
  }

  server {
    # use 'listen 80 deferred;' for Linux
# use 'listen 80 deferred;' for Linux
# use 'listen 80 accept_filter=httpready;' for FreeBSD
listen 80;
client_max_body_size 4G;

# set the correct host(s) for your site
server_name 192.168.1.17;

keepalive_timeout 5;

# path for static files
root /webapps/mypolls/app/static/;

location / {
  include  /etc/nginx/mime.types;
  # checks for static file, if not found proxy to app
  try_files $uri @proxy_to_app;
}
    location / {
  include  /etc/nginx/mime.types;
  # checks for static file, if not found proxy to app
  try_files $uri @proxy_to_app;
}

location @proxy_to_app {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  # enable this if and only if you use HTTPS
  # proxy_set_header X-Forwarded-Proto https;
  proxy_set_header Host $http_host;
  # we don't want nginx trying to do something clever with
  # redirects, we set the Host: header above already.
  proxy_redirect off;
  proxy_pass http://app_server;
}

error_page 500 502 503 504 /500.html;
location = /500.html {
  root /webapps/mypolls/app/static/;
  }
 }
}

由于某种原因,对静态文件的请求仍然传递给gunicorn:

  

[2017-02-08 15:54:33 +0100] [2207] [DEBUG] GET /static/polls/style.css

似乎找到了感觉但是提供了空文件。配置有问题吗?

0 个答案:

没有答案