0

bottleFastCGI に移行したいベースの Web アプリケーションがあります。

# coding=utf-8
import bottle

class Webserver:
    def __init__(self):
        bottle.route('/api', ['GET', 'OPTIONS'], self.data)
        bottle.run(host='127.0.0.1', port=8081, debug=True, quiet=False)

    def data(self):
        return "hello"

    @bottle.error(404)
    def error404(error):
        print("404 Not Found from {0} @ {1}".format(bottle.request.remote_addr, bottle.request.url))

Webserver()

期待どおりに動作します。

それを FastCGI に移動して、run()呼び出しを変更しました。

# coding=utf-8
import bottle

class Webserver:
    def __init__(self):
        bottle.route('/api', ['GET', 'OPTIONS'], self.data)
        bottle.run(server='flup', host='127.0.0.1', port=8081, debug=True, quiet=False)

    def data(self):
        return "hello"

    @bottle.error(404)
    def error404(error):
        print("404 Not Found from {0} @ {1}".format(bottle.request.remote_addr, bottle.request.url))

Webserver()

フロント Web サーバーlighttpdとその完全な構成は次のとおりです。

root@domotique /e/lighttpd# cat lighttpd.conf
server.modules = (
        "mod_access",
        "mod_alias",
        "mod_compress",
        "mod_redirect",
#       "mod_rewrite",
        "mod_fastcgi",
        "mod_accesslog",
)


server.document-root        = "/var/www/html"
server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
server.errorlog             = "/var/log/lighttpd/error.log"
server.pid-file             = "/var/run/lighttpd.pid"
server.username             = "www-data"
server.groupname            = "www-data"
server.port                 = 80
accesslog.filename          = "/var/log/lighttpd/access.log"

index-file.names            = ( "index.php", "index.html", "index.lighttpd.html" )
url.access-deny             = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )

compress.cache-dir          = "/var/cache/lighttpd/compress/"
compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )

# default listening port for IPv6 falls back to the IPv4 port
## Use ipv6 if available
#include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

fastcgi.server = (
    "/api" =>
        (
                (
                    "host" => "127.0.0.1",
                    "port" => 8081,
                    "check-local" => "disable"
                )
        )
)

両方lighttpdと私の Python スクリプトが machine10.200.0.7で実行されている場合、http 呼び出しを発行すると、次のようになります。

root@srv ~# http 10.200.0.7/api
HTTP/1.1 404 Not Found
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Date: Thu, 22 Dec 2016 08:02:20 GMT
Server: lighttpd/1.4.35

の観点からlighttpd:

root@10.200.0.7# cat /var/log/lighttpd/access.log
10.200.0.1 10.200.0.7 - [22/Dec/2016:08:02:20 +0000] "GET /api HTTP/1.1" 404 0 "-" "HTTPie/0.9.2"

そしてpythonスクリプトから:

root@10.200.0.7# python3 wtest.py
Bottle v0.12.7 server starting up (using FlupFCGIServer())...
Listening on http://127.0.0.1:8081/
Hit Ctrl-C to quit.

404 Not Found from 10.200.0.1 @ http://10.200.0.7/api/

そのため、コールは を通過し、lighttpdに到達し、パスが不明であるかのようwtest.pyに を発行します。404一方、直接開始した場合 (flup同じルーティングを使用せずに)、 を返しますhello

この行動の違いはどこから来るのでしょうか?

4

1 に答える 1