【问题标题】:Accessing bottle app using mod_wsgi使用 mod_wsgi 访问瓶子应用程序
【发布时间】:2014-10-17 09:32:41
【问题描述】:

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(使用bottle框架实现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()

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

我需要在 server.py 中进行哪些更改以便只使用端口 8081? 我已经尝试过使用 application = bottle.default_app() 但每当我调用“helloworld”api 时,我都会在 apache2 error.log 中收到“500 Internal Server Error”和以下错误:

[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

求救!!!

【问题讨论】:

    标签: python django apache mod-wsgi bottle


    【解决方案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"
    

    【讨论】:

    • 这看起来仍然很可疑,因为“应用程序”只会设置在 launch() 函数的本地堆栈中,而不是在全局范围内,即使那样,这也不会发生,因为 launch() 是现在没有根据您显示的内容调用。 bottlepy.org/docs/dev/deployment.html#apache-mod-wsgi 的文档根本没有显示 launch() 函数,而是在全局范围内设置应用程序。因此,只需按照文档进行操作即可。
    • 感谢 Graham 指出这一点。这是一个错字。我摆脱了启动功能并直接调用 default_app() (如上面编辑后的帖子所示)
    猜你喜欢
    • 2012-08-03
    • 1970-01-01
    • 2014-02-24
    • 2014-02-27
    • 2018-10-06
    • 2018-07-08
    • 2013-11-05
    • 2012-09-21
    • 2020-02-05
    相关资源
    最近更新 更多