我正在使用webapp2
来开发我的应用,我想使用mod_wsgi
将其部署在apache上,但我发现500内部服务器错误以及导入webapp2没有找到模块error_log中的错误。
我已将WebOb
,Paste
,webapp2
安装到系统以及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()