使用mod_wsgi访问瓶子应用程序

时间:2014-08-23 19:10:32

标签: python django apache mod-wsgi bottle

的httpd.conf

Listen 8081
NameVirtualHost *:8081

<VirtualHost *:8081>
    ServerName ubuntu.com

    WSGIDaemonProcess kenobi user=www-data group=www-data processes=1 threads=5
    WSGIScriptAlias / /var/www/kenobi/app.wsgi

    <Directory /var/www/kenobi>
        WSGIProcessGroup kenobi
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>

app.wsgi

import os, sys

# Change working directory so relative paths (and template lookup) work again
sys.path.append('/var/www/kenobi')
os.chdir(os.path.dirname(__file__))
print sys.path


import server
print "launching..."
application = server.launch()
print "done"

server.py(使用瓶子框架实现rest api的脚本)

@route('/helloworld', method='GET')
def get_service_host_list():
    return("hello world")

def launch():
    print "attaching to server"
    run(host="192.168.45.111", port="8085", debug=True)
    #application = bottle.default_app()

所以上面的代码工作正常,除了它使用两个端口 - mod_wsgi使用8081来启动server.py和 server.py侦听的8085端口

我需要在server.py中进行哪些更改才能使用端口8081? 我已经尝试过使用application = bottle.default_app()但是我得到了&#34; 500内部服务器错误&#34;在apache2 error.log中出现以下错误,每当我打电话给#34; helloworld&#34; API:

[Sat Aug 23 12:05:17 2014] [error] launching...
[Sat Aug 23 12:05:17 2014] [error] attaching to server
[Sat Aug 23 12:05:17 2014] [error] done
[Sat Aug 23 12:05:17 2014] [error] [client 192.168.42.135] mod_wsgi (pid=35700):     Exception occurred processing WSGI script '/var/www/kenobi/app.wsgi'.
[Sat Aug 23 12:05:17 2014] [error] [client 192.168.42.135] TypeError: 'NoneType' object     is not callable

帮助!!!

1 个答案:

答案 0 :(得分:1)

哎呀必须做以下更改才能让这件事工作: 将server.py中的def launch()更改为

print "attaching to server"
application = bottle.default_app()

在app.wsgi FROM

中替换以下内容
import server
print "launching..."
application = server.launch()
print "done"

print "launching..."
from server import application
print "done"