webapp2 mod_wsgi apache centos 500内部服务器错误; wsgi脚本无法作为Python模块加载

时间:2016-06-09 06:42:34

标签: python apache mod-wsgi webapp2

我正在使用webapp2来开发我的应用,我想使用mod_wsgi将其部署在apache上,但我发现500内部服务器错误以及导入webapp2没有找到模块error_log中的错误。

我已将WebObPastewebapp2安装到系统以及virtualenv并在python环境中进行了测试

>> import webapp2 

它工作正常。

错误是:

> mod_wsgi (pid=15727): Target WSGI script '/var/www/html/app/main.py'
> cannot be loaded as Python module.
>     mod_wsgi (pid=15727): Exception occurred processing WSGI script '/var/www/html/app/main.py'.Traceback (most recent call last):File
> "/var/www/html/app/main.py", line 20, in <module>
>     import webapp2

我的httpd.conf文件配置位于

之下
WSGISocketPrefix /var/run/wsgi
WSGIPythonPath /var/www/html/app/env/lib/python2.7/site-packages

<VirtualHost 10.10.10.9>
    ServerName prep2016.msitprogram.net
    ServerAlias prep2016.msitprogram.net
    ServerAdmin sirimala.sreenath@gmail.com
#    DocumentRoot /var/www/html/app

    #WSGIDaemonProcess app python-path=/var/www/html/app:/var/www/html/app/env/lib/python2.7/site-packages
    WSGIDaemonProcess prep2016.msitprogram.net processes=2 threads=15
    WSGIScriptAlias / /var/www/html/app/main.py
    <Directory /var/www/html/app/>
#       options +ExecCGI
#       DirectoryIndex main.py
#       Order allow,deny
#       Allow from all  
#    </Directory>
#    DocumentRoot /var/www/html/app
#    WSGIDaemonProcess prep2016.msitprogram.net processes=2 threads=15 
    #WSGIDaemonProcess prep2016.msitprogram.net user=apache group=apache processes=2 threads=15 
    WSGIProcessGroup prep2016.msitprogram.net
    WSGIApplicationGroup %{GLOBAL}
    WSGIScriptReloading On
#    WSGIScriptAlias / /var/www/html/app/main.py
#    WSGIPythonPath /var/www/html/app

#    <Directory /var/www/html/app>
#       <Files main.py>
        Order allow,deny
        Allow from all
#       Require all granted
#       </Files>    
</Directory>
</VirtualHost>

这是我的main.py文件内容

#!/usr/bin/env python

import os
import webapp2
import jinja2
import logging
import json
import datetime
import jwt.api_jwt
import os, sys
ABSPATH = os.path.dirname (__ file__)
sys.path.append (ABSPATH)
os.chdir (ABSPATH)
sys.path.append('/var/www/html/app/env/lib/python2.7/site-packages')
#site.addsitedir('/var/www/html/app/env/lib/python2.7/site-packages')

class MainPage(Webapp2.RequestHandler):
        def get(self):
                self.response.out.write("hello world")

app = webapp2.WSGIApplication([
    ('/', MainPage),
], debug=True)

def main():
    from paste import httpserver
    httpserver.serve(app, host='prep2016.msitprogram.net', port='8080')

if __name__ == '__main__':
    main()

0 个答案:

没有答案