我有一个尴尬的设置与Apache 2的networking服务器是守门人和代理stream量基于传入的域名:
<VirtualHost *:80> ServerName example.org RewriteEngine On RewriteRule ^/(.*) http://localhost:3000/$1 [P] </VirtualHost>
在localhost:3000下运行我有一个lighttpd运行,它提供静态内容,并作为其他两个服务的反向代理,在端口3001和3002上运行。configuration如下所示:
# lighttpd will also be used to forward requests to node.js server.modules = ( "mod_proxy" ) # This config is meant to work relative to certain directories, # it is not meant to be used somewhere globally in /etc/ var.projectRoot = var.CWD # Setting up paths server.document-root = var.projectRoot + "/client" # Port to listen on server.port = 3000 # We don't want to provide names of individual files index-file.names = ( "index.html" ) # Serve all API calls to the API server $HTTP["url"] =~ "^/api/.*$" { proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => 3001 ) ) ) } # Serve all pages that are not known as static or api routes # to the page instance $HTTP["url"] !~ "^/(assets|game|ige|api).*$" { proxy.server = ( "" => ( ( "host" => "127.0.0.1", "port" => 3002 ) ) ) }
整个设置工作正常以下情况:
GET /assets/textures/sources.txt从client目录提供静态文件。 GET /api/games/byId/123从端口3001上的API服务器获取正确的数据 GET /检索页面 但是,请求GET /game ( game文件夹有一个index.html文件)确实得到了服务,但将URL更改为http://localhost:3000/game 。 或者更确切地说:它改变为我在Apache2虚拟主机中指定的任何URL,如果我把example.org:3000放在那里,它将尝试服务example.org:3000/game ,忽略[P]代理指令。
当lighttpds“重写”为文件folder/请求提供folder/index.html文件时,事情只会出错。 有人可以告诉我为什么?
Chrome和Firefox的行为是一样的,我没有得到任何HTTPredirect。
这可能是由lighttpd服务器进行的一些redirect,因为您没有指定ProxyPassReverse指令(它也适用于RewriteRule )。 也就是说,我没有看到任何关于你的configuration,特别是需要mod_rewrite来执行这个代理:最好的做法是避免使用它时,有专门的指令来完成这项工作。
你介意试试这个吗?
<Location /> ProxyPass http://localhost:3000 ProxyPassReverse http://localhost:3000 </Location>