【问题标题】:httpd mod_wsgi python3 pyramid Service Temporary unavaliabehttpd mod_wsgi python3 金字塔服务临时 unavaliabe
【发布时间】:2016-03-21 16:55:54
【问题描述】:

我做了什么:

  1. 我下载了 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    
  1. 我已经使用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 form 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)
  1. 我在 /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

  1. 在 /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(参见最后一篇文章)),现在它在导入编码模块时遇到了问题

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,它不会抱怨 编码,但现在它会给出“内部服务器错误”

更新:终于找到了名称奇怪的日志“虚拟主机”,错误是我的配置中没有这一行WSGISocketPrefix /var/run/wsgi

【问题讨论】:

    标签: apache python-3.x mod-wsgi pyramid


    【解决方案1】:

    终于搞定了!

    调用日志文件(默认) dummy-host.example.com-error_log 并位于 apache 日志目录中

    这是我的配置(为简单起见,它们的设计没有虚拟主机)

    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(俄语)

    【讨论】:

      猜你喜欢
      • 2014-01-15
      • 2014-06-18
      • 1970-01-01
      • 1970-01-01
      • 2016-07-21
      • 2014-06-18
      • 2018-03-07
      • 2015-01-03
      • 2013-07-02
      相关资源
      最近更新 更多