编辑:最后我解决了这个问题,并在下面发布了解决方案。
我有一个 gollum wiki,由 sinatra 服务器在 localhost 端口 4567 上提供服务。我想让它可以通过 www.mysite.com/wiki 从外部世界访问
我在 Ubuntu 12.04 上运行了 appache-2.2 服务器,并启用了 mod_proxy 和 mod_proxy_http。
我的 vhosts.conf 包含:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/mysite
ServerName www.mysite.pl
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /wiki/ http://localhost:4567/
ProxyPassReverse /wiki/ http://localhost:4567/
ProxyHTMLURLMap http://localhost:4567 /wiki
<Location /wiki>
Order allow,deny
Allow from all
RequestHeader unset Accept-Encoding
SetOutputFilter proxy-html
ProxyPass http://localhost:4567
ProxyPassReverse /wiki
ProxyHTMLURLMap / /wiki/
ProxyHTMLURLMap /wiki /wiki
ProxyHTMLURLMap http://localhost:4567 /wiki
</Location>
<Directory / >
AllowOverride AuthConfig FileInfo Indexes Limit Options
Order allow,deny
allow from all
</Directory>
LogLevel debug
ScriptAlias /cgi-bin/ /var/www/mysite/cgi-bin/
<Directory /var/www/mysite/cgi-bin/>
AllowOverride None
Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /srv/src.git
ServerName git.mysite.com
DAVLockDB /var/lock/apache2/davlockDB
<Directory /srv/src.git >
DAV On
Options Indexes MultiViews
IndexOptions FancyIndexing
Order allow,deny
Allow from all
AuthType Basic
AuthName "git repository"
AuthUserFile /etc/apache2/passwd
Require valid-user
</Directory>
</VirtualHost>
Sinatra 日志表明,当我获取 www.mysite.com/wiki 时,确实访问了 localhost:4567 站点。但 apache 返回错误。Apache 日志显示:
[Sun Nov 09 02:04:01 2014] [debug] mod_proxy_http.c(56): proxy: HTTP: canonicalising URL //localhost:4567
[Sun Nov 09 02:04:01 2014] [debug] proxy_util.c(1506): [client 93.105.202.224] proxy: http: found worker http://localhost:4567 for http://localhost:4567/
[Sun Nov 09 02:04:01 2014] [debug] mod_proxy.c(1020): Running scheme http handler (attempt 0)
[Sun Nov 09 02:04:01 2014] [debug] mod_proxy_http.c(1973): proxy: HTTP: serving URL http://localhost:4567/
[Sun Nov 09 02:04:01 2014] [debug] proxy_util.c(2011): proxy: HTTP: has acquired connection for (localhost)
[Sun Nov 09 02:04:01 2014] [debug] proxy_util.c(2067): proxy: connecting http://localhost:4567/ to localhost:4567
[Sun Nov 09 02:04:01 2014] [debug] proxy_util.c(2193): proxy: connected / to localhost:4567
[Sun Nov 09 02:04:01 2014] [debug] proxy_util.c(2444): proxy: HTTP: fam 2 socket created to connect to localhost
[Sun Nov 09 02:04:01 2014] [debug] proxy_util.c(2576): proxy: HTTP: connection complete to 127.0.0.1:4567 (localhost)
[Sun Nov 09 02:04:01 2014] [debug] mod_proxy_http.c(1743): proxy: start body send
[Sun Nov 09 02:04:01 2014] [debug] mod_proxy_http.c(1847): proxy: end body send
[Sun Nov 09 02:04:01 2014] [debug] proxy_util.c(2029): proxy: HTTP: has released connection for (localhost)
[Sun Nov 09 02:04:01 2014] [error] [client 93.105.202.224] File does not exist: /var/www/Home
gollum-wiki 正确返回了“主页”位置名称(作为其默认主页),有人能向我解释一下这种行为吗?
回答:它有助于将每次出现的 改为http://localhost:4567
。当我登录到我的 http 服务器并用于访问http://localhost:4567/wiki
时,我有一个想法尝试一下。它思考了几秒钟,然后返回
lynx
127.0.0.1:4567
127.0.0.1:4567/wiki/Home
答案1
看起来像:
- 您的访客点击http://www.mysite.pl/wiki/
- 这将传递给在 localhost:4567 运行的 gollum 实例。
- gollum wiki 看到你正在访问首页,并重定向到 /Home
- 这会导致浏览器访问http://mysite.pl/首页
- 它缺失了,并且位于 /wiki/ 前缀之外,因此显示 404。
解决方案是确保将其/wiki
添加到 gollum-pages 的前面。像这样启动它:
$ gollum --host 127.0.0.1 --port 4567 --base-path wiki
PS. 您也不需要在您的 Apache 配置中指定“ProxyHTMLURLMap”;ProxyPass 和 ProxyPassReverse 就足够了。