Dan*_*ain 5 python django nginx uwsgi
环境: 在Windows 10主机上的Vagrant / Virtualbox中运行的Ubuntu 16.04(系统Python在2.7.12)
Python安装程序: 通过执行python -V验证了系统python,未激活virtualenv。还安装了Python 3.5,并且已经pipenv --three为该项目创建了virtualenv。在激活的virtualenv中进行python -V(pipenv shell激活)显示Python 3.5.2。
其他背景: 我正在开发Wagtail 2应用程序。Wagtail 2需要Django 2,而它当然需要Python3。我在这台机器上还有其他Django应用程序,这些应用程序是Django 1.11 / Python 2.7开发的,由Apache提供。我们将继续使用Django 2 / Python 3进行开发,并正在使用nginx / uWSGI来提供应用程序。
我经历了许多教程/许多迭代。所有的Vagrant端口映射都可以通过nginx提供媒体/静态文件并在Unix套接字上向Django应用传递请求到Django应用的设置很好地设置,但这会导致502 Gateway not found错误,因为uWSGI无法正确运行。因此,现在我只是在命令行中运行以下命令,以尝试运行uWSGI : uwsgi --ini /etc/uwsgi/sites/my_site.com.ini。该文件包含:
[uwsgi]
uid = www-data
gid = www-data
plugin = python35
# Django-related settings
# the base directory (full path)
chdir=/var/sites/my_site
# Django's wsgi file
wsgi-file = my_site.wsgi
# the virtualenv (full path)
virtualenv=/root/.local/share/virtualenvs/my_site-gmmiTMID
# process-related settings
# master
master = True
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe)
socket = /tmp/my_site.sock
# clear environment on exit
vacuum = True
Run Code Online (Sandbox Code Playgroud)
我尝试通过以下方式安装uWSGI:
pip install uwsgi以及pip3 install uwsgiapt-get install uwsgi uwsgi-plugin-python3通过卸载以前的uwsgi安装,我确保一次只能进行一次安装。后一种安装方法将uwsgi-core放置在usr / bin中,还将uwsgi,uwsgi_python3和uwsgi_python35的快捷方式放置在usr / bin中。
在.ini文件中,我也尝试过plugin = python3。我也从命令行尝试过:
uwsgi_python3 --ini /etc/uwsgi/sites/my_site.com.iniuwsgi_python35 --ini /etc/uwsgi/sites/my_site.com.ini我试过uwsgi ... .ini在激活的虚拟环境中和禁用virtualenv的情况下执行命令。这三个命令行uwsgi ... .ini执行(uwsgi ...,uwsgi_python3 ...和uwsgi_python35 ...)DO原因要执行的.ini文件,但每一次我发现了以下错误(下面的语句的最后两行):
[uwsgi] implicit plugin requested python35
[uWSGI] getting INI configuration from /etc/uwsgi/sites/my_site.com.ini
*** Starting uWSGI 2.0.12-debian (64bit) on [Wed Mar 7 03:54:44 2018] ***
compiled with version: 5.4.0 20160609 on 31 August 2017 21:02:04
os: Linux-4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018
nodename: vagrant-ubuntu-trusty-64
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /vagrant/my_site
detected binary path: /usr/bin/uwsgi-core
setgid() to 33
setuid() to 33
chdir() to /var/sites/my_site
your processes number limit is 7743
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /tmp/my_site.sock fd 3
Python version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
Set PythonHome to /root/.local/share/virtualenvs/my_site-gmmiTMID
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Run Code Online (Sandbox Code Playgroud)
如果我进入已激活的virtualenv内的Python命令行并执行import encodings,它将很好地导入(无消息-仅返回命令行)。搜索此特定错误没有发现任何用处。知道为什么ImportError:没有名为“ encodings”的模块出现吗?
更新-问题仍在发生
我正在使用pipenv,它将单个virtualenvs存储在该/home/username/.local/share/virtualenvs文件夹中。尽管我可以通过以无业游民的用户身份执行uWSGI配置文件来从命令行启动uWSGI(请参见下面的注释),但是我仍然无法/home/vagrant/.local/share/virtualenvs/my_venv在uWSGI配置文件中启动该服务。我尝试将无业游民的用户添加到www-data组,并将www-data航海家添加到无业游民组。我还在整个路径(包括单个venv)上都设置了对世界的读取和执行许可,但是uWSGI服务仍将无法启动。
哈克式变通
我终于通过将venv复制到来获得uWSGI服务/opt/virtualenvs/my_venv。这样,我便可以通过启动服务sudo service uwsgi start。整个路径的所有权是root:root。
仍在寻找解决方案...
该解决方案不是最佳选择,因为我现在正在从virtualenv执行,当默认virtualenv更新时,该环境必须更新,因为该位置不是pipenv的默认位置,因此我仍在寻找答案。也许这是Ubuntu权限错误,但我只是找不到问题。
anj*_*505 -1
可能是你的虚拟环境的问题。尝试以下操作
rm -rf /root/.local/share/virtualenvs/my_site-gmmiTMID
virtualenv -p python3 /root/.local/share/virtualenvs/my_site-gmmiTMID
source /root/.local/share/virtualenvs/my_site-gmmiTMID/bin/activate
pip install -r requirements.txt
Run Code Online (Sandbox Code Playgroud)
并在 uwsgi conf 中尝试更改
virtualenv=/root/.local/share/virtualenvs/my_site-gmmiTMID
Run Code Online (Sandbox Code Playgroud)
到
home=/root/.local/share/virtualenvs/my_site-gmmiTMID
Run Code Online (Sandbox Code Playgroud)
参考: http ://uwsgi-docs.readthedocs.io/en/latest/Options.html#virtualenv
| 归档时间: |
|
| 查看次数: |
1809 次 |
| 最近记录: |