nginx,gunicorn和django超时

时间:2015-09-26 07:13:23

标签: django nginx gunicorn

我很困惑! 我设置了一切,我的网站工作了两天,然后突然今天它停止工作。 我唯一改变的是昨天我试图提供PHP文件,所以我安装了PHP和uwsgi。已经很晚了,我没有意识到自己在做什么。它来自这个网站:http://uwsgi-docs.readthedocs.org/en/latest/PHP.html

# Add ppa with libphp5-embed package
sudo add-apt-repository ppa:l-mierzwa/lucid-php5
# Update to use package from ppa
sudo apt-get update
# Install needed dependencies
sudo apt-get install php5-dev libphp5-embed libonig-dev libqdbm-dev
# Compile uWSGI PHP plugin
python uwsgiconfig --plugin plugins/php

但没有改变任何设置。即便这样做,一切仍然很好。但是第二天,我的网站只是没有加载。

我尝试了一些不起作用的东西。在我的设置中:

ALLOWED_HOSTS = ['*']


在我的gunicorn.sh中,我设置TIMEOUT = 60。但是,当我尝试访问我的网站(lewischi.com)时,甚至都没有发生。但是当我去http://127.0.0.1:8000时,我确实看到工人做了什么并得到了404错误。

Using the URLconf defined in django_project.urls, 
Django tried these URL patterns, in this order: 


我不确定发生了什么! nginx-error日志不是很有用,但访问日志似乎更有用。

从我的nginx-access.log(它可以工作,然后停止工作):

50.156.86.221 - - [25/Sep/2015:00:25:43 -0700] "GET /codeWindow.html 
HTTP/1.1" 200 2081 "http://lewischi.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) 
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"
50.156.86.221 - - [25/Sep/2015:00:25:58 -0700] "GET /test.jpg HTTP/1.1" 
404 208 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 
(KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"
192.168.2.6 - - [25/Sep/2015:16:42:19 -0700] "GET / HTTP/1.1" 200 9596 "-" "-"
192.168.2.6 - - [25/Sep/2015:17:24:44 -0700] "GET / HTTP/1.1" 200 9596 "-" "-"
192.168.2.6 - - [25/Sep/2015:23:28:51 -0700] "GET / HTTP/1.1" 200 9596 "-" "-"
192.168.2.6 - - [25/Sep/2015:23:29:02 -0700] "GET / HTTP/1.1" 200 9596 "-" "-"


从我的主管日志文件:

supervisor: couldn't exec /home/lewischi/projects/active/django_project/gunicorn.sh: ENOEXEC   
supervisor: child process was not spawned

任何帮助将不胜感激!!!!我觉得我应该卸载uwsgi。我不想打破任何东西,所以在我弄乱之前我会征求意见。


我对此很陌生,所以我可能会忽略一些显而易见的事情。我的gunicorn调试模式输出:

    “Starting ”djangotut” as lewischi”
[2015-09-26 17:50:28 +0000] [2316] [DEBUG] Current configuration:
  proxy_protocol: False
  worker_connections: 1000
  statsd_host: None
  max_requests_jitter: 0
  post_fork: <function post_fork at 0x7faf049ec848>
  pythonpath: None
  enable_stdio_inheritance: False
  worker_class: sync
  ssl_version: 3
  suppress_ragged_eofs: True
  syslog: False
  syslog_facility: user
  when_ready: <function when_ready at 0x7faf049ec578>
  pre_fork: <function pre_fork at 0x7faf049ec6e0>
  cert_reqs: 0
  preload_app: False
  keepalive: 2
  accesslog: None
  group: 1000
  graceful_timeout: 30
  do_handshake_on_connect: False
  spew: False
  workers: 3
  proc_name: ”djangotut”
  sendfile: True
  pidfile: None
  umask: 0
  on_reload: <function on_reload at 0x7faf049ec410>
  pre_exec: <function pre_exec at 0x7faf049ecde8>
  worker_tmp_dir: None
  post_worker_init: <function post_worker_init at 0x7faf049ec9b0>
  limit_request_fields: 100
  on_exit: <function on_exit at 0x7faf049f2500>
  config: None
  secure_scheme_headers: {'X-FORWARDED-PROTOCOL': 'ssl', 'X-FORWARDED-PROTO': 'https', 'X-FORWARDED-SSL': 'on'}
  proxy_allow_ips: ['127.0.0.1']
  pre_request: <function pre_request at 0x7faf049ecf50>
  post_request: <function post_request at 0x7faf049f20c8>
  user: 1000
  forwarded_allow_ips: ['127.0.0.1']
  worker_int: <function worker_int at 0x7faf049ecb18>
  threads: 1
  max_requests: 1
  limit_request_line: 4094
  access_log_format: %(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"
  certfile: None
  worker_exit: <function worker_exit at 0x7faf049f2230>
  chdir: /home/lewischi/projects/active/django_project
  paste: None
  default_proc_name: django_project.wsgi:application
  errorlog: -
  loglevel: DEBUG
  logconfig: None
  syslog_addr: udp://localhost:514
  syslog_prefix: None
  daemon: False
  ciphers: TLSv1
  on_starting: <function on_starting at 0x7faf049ec2a8>
  worker_abort: <function worker_abort at 0x7faf049ecc80>
  bind: ['0.0.0.0:8000']
  raw_env: []
  reload: False
  check_config: False
  limit_request_field_size: 8190
  nworkers_changed: <function nworkers_changed at 0x7faf049f2398>
  timeout: 60
  ca_certs: None
  django_settings: None
  tmp_upload_dir: None
  keyfile: None
  backlog: 2048
  logger_class: gunicorn.glogging.Logger
  statsd_prefix: 
[2015-09-26 17:50:28 +0000] [2316] [INFO] Starting gunicorn 19.3.0
[2015-09-26 17:50:28 +0000] [2316] [DEBUG] Arbiter booted
[2015-09-26 17:50:28 +0000] [2316] [INFO] Listening at: http://0.0.0.0:8000 (2316)
[2015-09-26 17:50:28 +0000] [2316] [INFO] Using worker: sync
[2015-09-26 17:50:28 +0000] [2327] [INFO] Booting worker with pid: 2327
[2015-09-26 17:50:28 +0000] [2328] [INFO] Booting worker with pid: 2328
[2015-09-26 17:50:28 +0000] [2329] [INFO] Booting worker with pid: 2329
[2015-09-26 17:50:29 +0000] [2316] [DEBUG] 3 workers
[2015-09-26 17:50:30 +0000] [2316] [DEBUG] 3 workers

2 个答案:

答案 0 :(得分:0)

问题不在于supervisord本身,在处理Nginx,Gunicorn和Django时一般要考虑的事情很少:

  1. 确保用户正在运行应用程序进程(最少1个非root用户,不包括默认创建的用户,例如:Nginx,Postgresql。堆栈更改)具有正确的权限和所有权以实现其目标。
  2. 在您的堆栈中添加其他应用程序时,您应首先检查它默认运行的端口,并更改它以防止端口冲突,请记住内部和外部端口之间的区别,因为您使用Nginx作为Gunicorn的代理(这是导致大多数超时的原因,在深夜工作中多次发生在我身上),您可以使用Nginx作为代理服务器,并为每个应用创建许多具有不同唯一内部端口的应用。
  3. 使用您为主管提供的错误日志,您似乎正在使用没有足够权限或所有权的用户或使用错误命令执行的gunicorn.sh。

    请提供与您的应用相关的主管配置文件。

    更新:似乎他的IP地址已更改。

答案 1 :(得分:0)

啊没关系。谢谢你的时间。 事实证明,我的IP地址以某种方式改变了哪些不应该发生....新秀错误。