我正在尝试使用Nginx网络服务器在Ubuntu 16.04系统上部署django网站,但我遇到了问题。我对系统管理很陌生。
错误
我从我的nginx error.log文件中获取错误:
connect() to unix:/home/teddycrepineau/contoursandcolors/contoursandcolors.sock failed (13: Permission denied) while connecting to upstream, client: 64.125.191.37, server: 173.255.210.63, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/home/teddycrepineau/contoursandcolors/contoursandcolors.sock:", host: "173.255.210.63", referrer: "http://173.255.210.63/"
uwsgi状态
uwsgi[25361]: thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi[25361]: uwsgi socket 0 bound to UNIX address /home/teddycrepineau/contoursandcolors/contoursandcolors.sock fd 3
uwsgi[25361]: Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
uwsgi[25361]: !!! Python Home is not a directory: /home/teddycrepineau/Env/contoursandcolors !!!
uwsgi[25361]: Set PythonHome to /home/teddycrepineau/Env/contoursandcolors
uwsgi[25361]: Fatal Python error: Py_Initialize: Unable to get the locale encoding
uwsgi[25361]: ImportError: No module named 'encodings'
uwsgi[25361]: Current thread 0x00007f0ec8429700 (most recent call first):
uwsgi[25361]: Thu Apr 12 13:31:57 2018 - [emperor] curse the uwsgi instance contoursandcolors.ini (pid: 4955)
uwsgi[25361]: Thu Apr 12 13:32:00 2018 - [emperor] removed uwsgi instance contoursandcolors.ini
设置
Virtualenvwrapper设置
echo "export WORKON_HOME=~/Env" >> ~/.bashrc
echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc
/etc/uwsgi/sites/contoursandcolors.ini
[uwsgi]
project = contoursandcolors
uid = teddycrepineau
base = /home/%(uid)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 2
socket = %(base)/%(project)/%(project).sock
chmod-socket = 664
vacuum = true
/ etc / nginx / sites-available / contoursandcolor文件设置
server {
listen 80;
server_name 173.255.210.63;
location = /favicon.io { access_log off; log_not_found off; }
location /static/ {
root /home/teddycrepineau/contoursandcolors;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/teddycrepineau/contoursandcolors/contoursandcolors.sock;
}
}
/etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown teddycrepineau:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
我做了什么
根据我的阅读,我的问题可能与virtuaenv位置设置有关,但我不确定如何解决这个问题。
答案 0 :(得分:0)
我最终使用的是gunicorn(而不是uWSGI)。它运行良好,很容易设置。以下是我使用的教程的链接:https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04