nginx、gunicorn 和 django 超时

nginx, gunicorn and django timing out

我很困惑! 我设置了一切,我的网站工作了两天,然后今天突然停止工作。 我唯一改变的是昨天我试图提供 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 错误日志不是很有用,但访问日志似乎更有用。

来自我的 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

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

  1. 确保用户 运行 应用程序进程(至少 1 个非 root 用户,不包括默认创建的用户,例如:Nginx、Postgresql。随堆栈变化)具有实现它的正确权限和所有权目标。
  2. 将另一个应用程序添加到您的堆栈时,您应该首先检查它默认运行的端口,并更改它以防止端口冲突,请记住内部和外部端口之间的区别,因为您使用 Nginx 作为代理到 Gunicorn(这是导致大多数超时的原因,我在深夜工作时发生过几次),你可以使用 Nginx 作为代理服务器,并为每个应用程序创建许多具有不同唯一内部端口的应用程序应用

根据您为主管提供的错误日志,您似乎 运行 您的 gunicorn.sh 要么与没有足够权限或所有权的用户一起使用,要么执行了错误的命令.

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

更新: 好像他的IP地址变了。

啊,没关系。谢谢你的时间。 原来我的 ip 地址不知何故发生了变化,这本不应该发生的……菜鸟错误。