webapp2 mod\wsgi apache centos 500内部服务器错误;无法将wsgi脚本作为Python modu加载

2024-09-28 03:20:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用webapp2来开发我的应用程序,我想用mod_wsgi将其部署到apache上,但是我在错误日志中遇到了500个内部服务器错误以及import webapp2 no module found Error。在

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

>> import webapp2 

而且效果很好。在

错误是:

^{pr2}$

我的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()

Tags: pyimportenvappnetmainvarlib

热门问题