【问题标题】:Apache VirtualHost subdomain forwarding to Mercurial cgi scriptApache VirtualHost 子域转发到 Mercurial cgi 脚本
【发布时间】:2013-08-24 12:57:13
【问题描述】:

我需要通过 Apache VirtualHost 子域以及授权连接我的 Mercurial 服务器 cgi 脚本。

我的 apache 在 80 和 91 上运行。 Apache 通过

为 Mercurial 提供服务

C:\wamp\bin\apache\Apache2.2.21\cgi-bin\hgweb.cgi 并且可以通过

访问

http://my.com/cgi-bin/hgweb.cgihttp://localhost/cgi-bin/hgweb.cgi

一切都很好,它在那里完美地发挥了作用。我的目标是将其子域设置为:

http://hg.my.com/

没有尾随 cgi-bin/hgweb.cgi

我已获得以下 URL 以使用下面给出的配置:

http://hg.my.com/cgi-bin/hgweb.cgi

...但它无法正确访问 css 和图像(与上述完美服务不同)

到目前为止我的配置:

ScriptAlias /hg "/cgi-bin/hgweb.cgi"
<VirtualHost *:80>
ServerName hg.my.com
ServerAlias hg.my.com

#ScriptAlias / "/cgi-bin/hgweb.cgi"
#  <Directory />
#   Order Deny,Allow
#   Allow from all
#  </Directory>

#        ProxyPass /stylesheets !
#        ProxyPass /javascripts !
#        ProxyPass /images !

ProxyPassMatch ^.*/static(/.*\.css)$ http://localhost:91/cgi-bin/hgweb.cgi/static/$1
ProxyPassMatch ^.*/static(/.*\.js)$ http://localhost:91/cgi-bin/hgweb.cgi/static/$1
ProxyPassMatch ^.*/static(/.*\.png)$ http://localhost:91/cgi-bin/hgweb.cgi/static/$1
ProxyPassMatch ^.*/static(/.*\.gif)$ http://localhost:91/cgi-bin/hgweb.cgi/static/$1

ProxyPreserveHost On
ProxyPass / http://localhost:91/cgi-bin/hgweb.cgi
ProxyPassReverse / http://localhost:91/cgi-bin/hgweb.cgi
<Proxy *>
  #DirectoryIndex hgweb.cgi
    #ScriptAlias / /hgweb.cgi
# #  Order Allow,Deny
# #  Allow from all
    Order Deny,Allow
    Allow from 127.0.0.1
    AuthUserFile C:\wamp\.htpasswd
    AuthName "Please Log In"
    AuthType Basic

    require user admin
    require user dev

 </Proxy>
</VirtualHost>

显然,我使用的是久负盛名的 google-trial-and-error 方法,在这里我已经超出了我的深度。

因此,我精力充沛的自我无意识的自力更生决心,否则似乎很管用,现在已经筋疲力尽,对手头的问题充满敌意——带着帽子,我来到这里,问:

“兄弟,你能不能省点钱?”

【问题讨论】:

    标签: apache mercurial cgi


    【解决方案1】:

    为什么要在 80 和 91 上都运行 apache? 91只是为了提供静态内容吗?除非我遗漏了您的一项要求,否则您应该能够通过以下方式做任何您需要的事情:

    <VirtualHost *:80>
    ServerName hg.my.com
    
    ScriptAlias / "/cgi-bin/hgweb.cgi"
    
    <Location />
        Order Deny,Allow
        AuthUserFile C:\wamp\.htpasswd
        AuthName "Please Log In"
        AuthType Basic
    
        require user admin
        require user dev
    
    </Location>
    </VirtualHost>
    

    您不应该需要代理或单独的静态规则(Mercurial 会很好地为它们提供服务)。

    【讨论】:

    • 我尝试了你的代码,但它在位置上卡住了,所以我从 orig.conf 一步一步返回并弄清楚如何做我想做的事——但我不得不把 hgweb DocumentRoot 中的 .cgi。我的直觉告诉我这是一件坏事,这是什么故事?
    • 只要您拥有该 ScriptAlias,无论如何都不会从文档根目录提供文件,但您可能只使用 块来授权访问该目录,而不是使用 DirectoryRoot。我的位置标签有什么问题。我没有检查语法,但这是最好的方法,应该可以工作。
    • 我正在使用 wamp 和 Apache 2.2.21 -- 我没有查看日志,但它无法启动。我正在使用AddHandler cgi-script .cgi,然后在&lt;Directory "c:/wamp/www"&gt; 上使用Options ExecCGI。我没有为 hg.my.com 使用 VH,因为它似乎将我带到了与我的其他 VH 不匹配的任何子域——这对我来说是什么都可以。我想我现在可以更多地调整它,因为我对 VH 语法有了更多的了解。我不得不“非身份验证”我在配置中稍后发生的其他 VH 根——我是否理解设置会像那样级联?
    • 如果你对它的工作方式感到满意,你就完成了,但对于任何未来的搜索者:虚拟主机的顺序定义了默认值,所以让你的“主”站点最后,并使用ScriptAlias 比 AddHandler 更可取,因为后者意味着将 .cgi 放入 DocumentRoot 的攻击者已经破坏了您的系统,而使用 ScriptAlias 他们还需要更改您的 apache 配置,这通常要困难得多。
    【解决方案2】:

    在脚本后面加一个斜线: ScriptAlias /hg "/cgi-bin/hgweb.cgi/"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-14
      • 2015-03-04
      • 2018-07-20
      • 2017-06-03
      • 2017-02-17
      • 1970-01-01
      • 2012-11-14
      • 2020-04-09
      相关资源
      最近更新 更多