uwsgi配備に関する問題Fatal Python error:Py_Initialize:Unable to get the locale encoding問題(13:Permission denied)while connecting to upstream

8253 ワード

   uid    uwsgi,  
(flask) [root@localhost flask]# uwsgi uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.17.1 (64bit) on [Sun Oct 21 03:50:21 2018] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-28) on 20 October 2018 12:54:58
os: Linux-3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018
nodename: localhost.localdomain
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /var/flask
detected binary path: /root/.local/share/virtualenvs/flask-VGoRTHto/bin/uwsgi
setgid() to 995
setuid() to 997
chdir() to /var/flask/
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3802
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 /var/flask/flask.sock fd 3
Python version: 3.4.9 (default, Aug 14 2018, 21:28:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
!!! Python Home is not a directory: /root/.local/share/virtualenvs/flask-VGoRTHto/ !!!
Set PythonHome to /root/.local/share/virtualenvs/flask-VGoRTHto/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

Current thread 0x00007f03d1f7e840 (most recent call first):
   
uwsgi    
   [uwsgi] # Http access port. # If
this option comes into effect, we can visit our web site on http://[our IP]:[Port] # http=:5001 # Uwsgi's ip and port when it is loaded by Nginx socket=/var/flask/flask.sock chmod-socket=666 uid = nginx gid = nginx # Point to the main directory of the Web Site chdir=/var/flask/ # Setting up a virtual environment virtualenv=/root/.local/share/virtualenvs/flask-VGoRTHto/ # Python startup file wsgi-file=app.py # The application variable of Python Flask Core Oject callable=app # The maximum numbers of Processes processes=1 # The maximum numbers of Threads threads=2

 
原因を推測する:
iniファイルでユーザーnginxを切り替えると、仮想環境ディレクトリ権限の問題でpython仮想環境がシステムデフォルト環境になり、多くのライブラリが不足します.
解決方法:
他のユーザーxxxxにログインした後、pipenvはpython 3環境を新規作成し、ライブラリをインストールします.
cd /var/flask/
pipenv --python 3.4 pipenv shell pipenv install uwsgi msyql-connector-python flask

変更iniファイル:
uid = eledim
gid = eledim
virtualenv=/home/eledim/.local/share/virtualenvs/flask-VGoRTHto/ #      
$ uwsgi uwsgi.ini

 
その他の関連:
仮想環境でrootでuwsgiを起動します(推奨されない方法):
(flask) [root@localhost flask]#
uwsgi -s /var/flask/flask.sock -w app:app 
chmod 777 /var/flask/flask.sock

 
その他の質問:
また、ユーザの起動を切り替えると、古いsockファイルの権限がなく、socketバインドに失敗する可能性があります.古いsocketを削除する必要があります.
uwsgiの起動権限の問題を避けるために、sockファイルはrootディレクトリにあるべきではありません.他のサイトの関連ファイルは同じです.
nginxで権限の問題(13:Permission denied)が発生しないようにwhile connecting to upstream
nginxプロセスはroot所有を推奨せず、uwsgiを設定する必要があります.ini
chmod-socket=666

その他の理由:
setsebool -P httpd_can_network_connect 1
setenforce 0

リファレンスhttps://blog.csdn.net/kriszhang/article/details/68941793