与Gunicorn / Nginx的连接错误

时间:2016-09-07 11:55:16

标签: python django nginx gunicorn

我正在学习nginx并使用gunicorn配置nginx.conf。我在端口8000上运行gunicorn,在端口80上监听nginx。有时它工作正常,有时它会给出一个"无法连接"错误。

这是我的nginx.conf文件

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

events {
    worker_connections 768;
    # multi_accept on;

}


http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  

我有超级用户配置文件:   这是我的主管配置文件

[program:python-activate]
directory=<path of my directory>
command=/home/ashiyap/ianp3.sh gunicorn  proj.wsgi:application  -b 0.0.0.0:8000
autostart=true
autorestart=true
stderr_logfile=/var/log/supervisor.err.log
stdout_logfile=/var/log/supervisor.out.log
  

这是我的nginx python conf文件

server {
# the port your site will be served on
listen      80;
# the domain name it will serve for
server_name <ipaddress>;   # substitute by your FQDN and machine's IP address
charset     utf-8;
#Max upload size
client_max_body_size 75M;   # adjust to taste

# Django media
location /media  {
   root /home/ashiyap/test/wp005_v02.00.00.d2_itr1/proj;      # your Django project's media files
   autoindex off;
 }

location /static {
   root /home/ashiyap/test/wp005_v02.00.00.d2_itr1/proj;      # your Django project's static file
   autoindex off;
}

# Finally, send all non-media requests to the Django server.
location / {

    proxy_pass http://<ipaddress>:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

0 个答案:

没有答案