nginx django uwsgi 502坏网关

时间:2016-06-12 10:48:19

标签: django nginx uwsgi

我正在尝试使用nginx和uwsgi在ubuntu 14.04服务器64位上部署我的django Web应用程序。我遵循了this教程,但我收到了502错误的网关错误。

我遵循的步骤:

  1. 已安装的依赖关系和虚拟环境。
  2. 使用uwsgi命令尝试了django webapp:
  3. uwsgi --http :8001 --home /home/pnb/pnb --chdir /home/pnb/pnb/pnb -w pnb.wsgi

    1. 在目录/etc/uwsgi/sites中创建一个pnb.ini文件:
    2. [uwsgi]

      project = pnb    # Virtual environment name in home directory
      base = /home/pnb    # Home directory path
      chdir = /home/pnb/pnb     # Virtual Env Directory
      home = /home/pnb/pnb/pnb       #Django Project Directory with manage.py
      module = pnb.wsgi:application     # project name
      
      master = true
      processes = 5
      
      socket = /home/pnb/pnb/pnb/pnb.sock
      chmod-socket = 664
      vacuum = true
      
      1. 创建了一个新手脚本/etc/init/uwsgi.conf
      2. 描述“Emperor模式下的uWSGI应用服务器”

        start on runlevel [2345]
        stop on runlevel [!2345]
        
        setuid pnb
        setgid www-data
        
        exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
        
        1. created和nginx配置文件/etc/nginx/sites/available/pnb

          上游django {     server unix:/home/pnb/pnb/pnb/pnb.sock; }

          服务器{     听80;     server_name pnb.com; #IP地址或FQDN

          location /static/ {
              root /home/pnb/pnb/pnb;
          }
          
          location / {
              include         uwsgi_params;
              uwsgi_pass      unix:/home/pnb/pnb/pnb/pnb.sock;
          }
          

          }

        2. 使用此配置,当我访问pnb.com时,我收到502 bad gateway错误。

          有nginx错误日志:

          2016/06/12 06:30:10 [crit] 12517#0: *4 connect() to unix:/home/pnb/pnb/pnb/pnb.sock failed (2: No such file or directory) while connecting to upstream, client: 106.218.89.140, server: pnb.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/home/pnb/pnb/pnb/pnb.sock:", host: "pnb.com"
          

          如何更正此错误?

          编辑:

          现在我检查了pnb.sock文件没有在目录中创建。是否必须对文件权限执行某些操作?

          相同的配置适用于我的另一个项目。

0 个答案:

没有答案