httpd mod_wsgi python3金字塔服务临时unavaliabe

时间:2016-03-21 16:55:55

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

我刚刚做了什么:

  1. 我下载了python 3.5源代码,用
  2. 解压缩并编译它们

    `

    ./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

      但它完成了那样

    2. `

      /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)
      
      1. 我在/ srv / modwsgi / env中创建了virtualenv并安装了金字塔

        使用pcreate -s starter myapp创建了一个已启动的脚手架,激活了venv,运行python setup.py install并创建了guestbook.wsgi脚本

      2. 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 dir告知apache:apache

        1. 在/etc/httpd/conf.d/我创建了guestbook.conf
        2. `

          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>
          

          最后我在浏览器中运行它,然后说

          服务暂时不可用

          由于维护停机或容量问题,服务器暂时无法为您的请求提供服务。请稍后再试。 spiralarms.org端口80的Apache / 2.2.15(CentOS)服务器

          当我尝试访问此页面时,错误日志中没有新内容

          更新

          我尝试运行一个简单的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,它不会抱怨编码,但现在它会给出内部服务器错误&#39;

          更新:最后找到了名字奇怪的主机&#39;虚拟主机&#39;错误是我在配置WSGISocketPrefix /var/run/wsgi

          中没有这一行

1 个答案:

答案 0 :(得分:0)

终于开始工作了!

调用日志文件(默认情况下) dummy-host.example.com-error_log,位于apache日志目录

以下是我的配置(为简单起见,它们的设计没有VirtualHosts)

guestbook.conf for pyramid apps

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