httpd mod_wsgi python3 pyramid 服务暂时不可用
httpd mod_wsgi python3 pyramid Service Temporary unavaliabe
很快我做了什么:
- 我下载了 python 3.5 源代码,使用
提取并编译了它们
`
./configure --enable-shared --prefix=/usr/local/lib
make&&make install
Then python couldn't find a libpython3.5m.so.1.0 so i've ran
export LD_LIBRARY_PATH=/usr/local/lib
我使用 pip3.5 install mod_wsgi
安装了 mod_wsgi。
我还尝试使用
从源代码(从这里http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
)安装它
./configure --with-python=/usr/local/bin/python3.5
make
make install
但是就这样结束了
`
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_wsgi.la -rpath /usr/lib64/httpd/modules -module -avoid-version mod_wsgi.lo -L/usr/local/lib -L/usr/local/lib/python3.5/config -lpython3.5 -lpthread -ldl -lutil -lrt -lm
/usr/bin/ld: cannot find -lpython3.5
collect2: ld returned 1 exit status
apxs:Error: Command failed with rc=65536
...
所以我继续使用 modwsgi 形式的 pip 但 lld 说它仍然是第 2 python 所以在里面
`
(env) [root@spiralarms mod_wsgi-3.4]# ldd /usr/lib64/httpd/modules/mod_wsgi.so
linux-vdso.so.1 => (0x00007fffc3fae000)
libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00007fa1ea4c4000)
我在 /srv/modwsgi/env 中创建了 virtualenv 并安装了 pyramid
使用 pcreate -s starter myapp
、激活的 venv、运行 python setup.py install
创建了一个启动脚手架,并创建了 guestbook.wsgi 脚本
from pyramid.paster import get_app, setup_logging
ini_path = '/srv/env/bin/myapp/production.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')
然后我将整个 env 目录更改为 apache:apache
- 在 /etc/httpd/conf.d/ 中我创建了 guestbook.conf
`
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess guestbook user=apache group=apache threads=4 \
python-path=/srv/modwsgi/env/lib/python3.5/site-packages
WSGIPythonHome /srv/modwsgi/env/lib/python3.5/
WSGIScriptAlias /guestbook /srv/modwsgi/env/guestbook.wsgi
<Directory /srv/modwsgi/env>
WSGIProcessGroup guestbook
Order allow,deny
Allow from all
</Directory>
最后我在浏览器中 运行 它显示
服务暂时不可用
由于维护停机或容量问题,服务器暂时无法为您的请求提供服务。请稍后再试。
Apache/2.2.15 (CentOS) 服务器位于 spiralarms.org 端口 80
当我尝试访问此页面时,错误日志中没有任何新内容
更新:
我尝试了 运行 一个简单的 wsgi 应用程序
import sys
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'+str(sys.version_info)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
似乎 mod_wsgi 使用 python 2,但它应该使用 3。
更新:
我终于编译并安装了 modwsgi(按照这个 https://github.com/GrahamDumpleton/mod_wsgi/issues/101(见最后 post)),现在它在导入编码模块时遇到问题
Current thread 0x00007f45a4cfd7e0 (most recent call first):
[Mon Mar 21 16:33:56 2016] [notice] child pid 7325 exit signal Aborted (6)
[Mon Mar 21 16:33:56 2016] [notice] child pid 7326 exit signal Aborted (6)
[Mon Mar 21 16:33:56 2016] [notice] child pid 7327 exit signal Aborted (6)
Fatal Python error: Py_Initialize: Unable to get the locale encoding
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007f45a4cfd7e0 (most recent call first):
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007f45a4cfd7e0 (most recent call first):
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007f45a4cfd7e0 (most recent call first):
ImportError: No module named 'encodings'
更新: 没有 WSGIPythonHome 它不会抱怨 encodings 但现在它给出 'internal server error'
更新: 终于找到了具有奇怪名称 'dummy host' 的日志,错误是我的配置中没有这一行 WSGISocketPrefix /var/run/wsgi
终于成功了!
调用日志文件(默认)
dummy-host.example.com-error_log 并且位于 apache 日志目录
这是我的配置(为简单起见,它们在设计时没有使用 VirtualHosts)
guestbook.conf(金字塔应用)
LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/wsgi #don't forget this line
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess guestbook user=apache group=apache threads=4 \
python-path=/srv/modwsgi/env/lib/python3.5/site-packages
#python-path=/usr/local/lib/python3.5/site-packages
WSGIScriptAlias /guestbook /srv/modwsgi/env/guestbook.wsgi
<Directory /srv/modwsgi/env>
WSGIProcessGroup guestbook
Order allow,deny
Allow from all
</Directory>
这里是guestbook.wsgi
from pyramid.paster import get_app, setup_logging
ini_path = '/srv/modwsgi/env/guestbook-0.0/production.ini' #use a full path cause it will be runned from apache directory
setup_logging(ini_path)
application = get_app(ini_path, 'main')
对于非金字塔应用程序(显示我们的 python 版本的 hello world 示例)
hellowsgi.conf:
#LoadModule wsgi_module modules/mod_wsgi.so uncomment this if it's not in other configs or better put it in the global config
WSGIScriptAlias /hello /srv/modwsgi/hello.wsgi
hello.wsgi:
import sys
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'+str(sys.version_info)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [bytes(output,'utf-8')] # use bytes for python 3 wsgi
另外不要忘记为所有文件授予对 apache 的访问权限。
我已经写了 an article 关于这个(俄语)
很快我做了什么:
- 我下载了 python 3.5 源代码,使用 提取并编译了它们
`
./configure --enable-shared --prefix=/usr/local/lib
make&&make install
Then python couldn't find a libpython3.5m.so.1.0 so i've ran
export LD_LIBRARY_PATH=/usr/local/lib
我使用
pip3.5 install mod_wsgi
安装了 mod_wsgi。我还尝试使用
从源代码(从这里http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
)安装它./configure --with-python=/usr/local/bin/python3.5 make make install
但是就这样结束了
`
/usr/lib64/apr-1/build/libtool --silent --mode=link gcc -o mod_wsgi.la -rpath /usr/lib64/httpd/modules -module -avoid-version mod_wsgi.lo -L/usr/local/lib -L/usr/local/lib/python3.5/config -lpython3.5 -lpthread -ldl -lutil -lrt -lm
/usr/bin/ld: cannot find -lpython3.5
collect2: ld returned 1 exit status
apxs:Error: Command failed with rc=65536
...
所以我继续使用 modwsgi 形式的 pip 但 lld 说它仍然是第 2 python 所以在里面
`
(env) [root@spiralarms mod_wsgi-3.4]# ldd /usr/lib64/httpd/modules/mod_wsgi.so
linux-vdso.so.1 => (0x00007fffc3fae000)
libpython2.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00007fa1ea4c4000)
我在 /srv/modwsgi/env 中创建了 virtualenv 并安装了 pyramid
使用
pcreate -s starter myapp
、激活的 venv、运行python setup.py install
创建了一个启动脚手架,并创建了 guestbook.wsgi 脚本
from pyramid.paster import get_app, setup_logging
ini_path = '/srv/env/bin/myapp/production.ini'
setup_logging(ini_path)
application = get_app(ini_path, 'main')
然后我将整个 env 目录更改为 apache:apache
- 在 /etc/httpd/conf.d/ 中我创建了 guestbook.conf
`
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess guestbook user=apache group=apache threads=4 \
python-path=/srv/modwsgi/env/lib/python3.5/site-packages
WSGIPythonHome /srv/modwsgi/env/lib/python3.5/
WSGIScriptAlias /guestbook /srv/modwsgi/env/guestbook.wsgi
<Directory /srv/modwsgi/env>
WSGIProcessGroup guestbook
Order allow,deny
Allow from all
</Directory>
最后我在浏览器中 运行 它显示
服务暂时不可用
由于维护停机或容量问题,服务器暂时无法为您的请求提供服务。请稍后再试。 Apache/2.2.15 (CentOS) 服务器位于 spiralarms.org 端口 80
当我尝试访问此页面时,错误日志中没有任何新内容
更新:
我尝试了 运行 一个简单的 wsgi 应用程序
import sys
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'+str(sys.version_info)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
似乎 mod_wsgi 使用 python 2,但它应该使用 3。
更新: 我终于编译并安装了 modwsgi(按照这个 https://github.com/GrahamDumpleton/mod_wsgi/issues/101(见最后 post)),现在它在导入编码模块时遇到问题
Current thread 0x00007f45a4cfd7e0 (most recent call first):
[Mon Mar 21 16:33:56 2016] [notice] child pid 7325 exit signal Aborted (6)
[Mon Mar 21 16:33:56 2016] [notice] child pid 7326 exit signal Aborted (6)
[Mon Mar 21 16:33:56 2016] [notice] child pid 7327 exit signal Aborted (6)
Fatal Python error: Py_Initialize: Unable to get the locale encoding
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007f45a4cfd7e0 (most recent call first):
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007f45a4cfd7e0 (most recent call first):
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Current thread 0x00007f45a4cfd7e0 (most recent call first):
ImportError: No module named 'encodings'
更新: 没有 WSGIPythonHome 它不会抱怨 encodings 但现在它给出 'internal server error'
更新: 终于找到了具有奇怪名称 'dummy host' 的日志,错误是我的配置中没有这一行 WSGISocketPrefix /var/run/wsgi
终于成功了!
调用日志文件(默认) dummy-host.example.com-error_log 并且位于 apache 日志目录
这是我的配置(为简单起见,它们在设计时没有使用 VirtualHosts)
guestbook.conf(金字塔应用)
LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/wsgi #don't forget this line
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIDaemonProcess guestbook user=apache group=apache threads=4 \
python-path=/srv/modwsgi/env/lib/python3.5/site-packages
#python-path=/usr/local/lib/python3.5/site-packages
WSGIScriptAlias /guestbook /srv/modwsgi/env/guestbook.wsgi
<Directory /srv/modwsgi/env>
WSGIProcessGroup guestbook
Order allow,deny
Allow from all
</Directory>
这里是guestbook.wsgi
from pyramid.paster import get_app, setup_logging
ini_path = '/srv/modwsgi/env/guestbook-0.0/production.ini' #use a full path cause it will be runned from apache directory
setup_logging(ini_path)
application = get_app(ini_path, 'main')
对于非金字塔应用程序(显示我们的 python 版本的 hello world 示例)
hellowsgi.conf:
#LoadModule wsgi_module modules/mod_wsgi.so uncomment this if it's not in other configs or better put it in the global config
WSGIScriptAlias /hello /srv/modwsgi/hello.wsgi
hello.wsgi:
import sys
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'+str(sys.version_info)
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [bytes(output,'utf-8')] # use bytes for python 3 wsgi
另外不要忘记为所有文件授予对 apache 的访问权限。
我已经写了 an article 关于这个(俄语)