21

我正在尝试在 OSX 上使用 Apache2 配置 mod_mono。我想在同一个虚拟主机上运行多个 MVC3 项目,但由于某种原因,只有列出的第一个项目在工作。对此的任何帮助将不胜感激,因为没有太多关于此的文档。我尝试了很多不同的配置选项,但似乎都不起作用。

Listen *:9005
<VirtualHost *:9005>
  DocumentRoot "/Library/WebServer/vhosts/api"
  ServerName api
  MonoAutoApplication disabled

  Alias /gamecenter "/Library/WebServer/vhosts/api/gamecenter"
  AddMonoApplications gamecenter "/gamecenter:/Library/WebServer/vhosts/api/gamecenter"
  MonoServerPath gamecenter "/usr/bin/mod-mono-server4"
  MonoDebug gamecenter true
  MonoSetEnv gamecenter MONO_IOMAP=all
  MonoUnixSocket gamecenter-stage /tmp/mod_mono_server_gc
  <Location /gamecenter>
    Allow from all
    Order allow,deny
    MonoSetServerAlias gamecenter
    SetHandler mono
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
  </Location>

  Alias /gamecenter-stage "/Library/WebServer/vhosts/api/gamecenter-stage"
  MonoServerPath gamecenter-stage "/usr/bin/mod-mono-server4"
  MonoDebug gamecenter-stage true
  MonoSetEnv gamecenter-stage MONO_IOMAP=all
  AddMonoApplications gamecenter-stage "/gamecenter-stage:/Library/WebServer/vhosts/api/gamecenter-stage"
  MonoUnixSocket gamecenter-stage /tmp/mod_mono_server_gcs
  <Location /gamecenter-stage>
    Allow from all
    Order allow,deny
    MonoSetServerAlias gamecenter-stage
    SetHandler mono
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI "\.(?:gif|jpe?g|png)$" no-gzip dont-vary
  </Location>

  <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript
  </IfModule>
</VirtualHost>
4

1 回答 1

3

您的问题是您的别名和物理路径是相同的,因此 apache 不知道要提供哪一个。

注意:我是根据一般 Apache2 配置给出答案,而不是根据 mod_mono,也许 mod_mono 做了一些事情来防止这种情况发生,我之前没有在 *nix 框下设置 MVC 应用程序:-)

反正...

如果你看看你的路径配置,你有......

/Library/WebServer/vhosts/api
/Library/WebServer/vhosts/api/gamecenter
/Library/WebServer/vhosts/api/gamecenter-stage

如果没有您的别名,这些已经解析为您尝试映射的路径。

/Library/WebServer/vhosts/api  = /
/Library/WebServer/vhosts/api/gamecenter  = /gamecenter
/Library/WebServer/vhosts/api/gamecenter-stage  = /gamecenter-stage

然后你告诉 Apache

/ = /
/gamecenter = /gamecenter
/gamecenter-stage = /gamecenter-stage

当 Apache 尝试传递内容时,如果没有文件子修复或现有斜杠(如最后 2 个),它将自动使用 / 为文件夹添加子修复,然后发出重定向(我相信是 306)基本上告诉浏览器从 EG 重定向:

/gamecenter to /gamecenter/

有了别名,告诉它 Alias ... 位于位置 x,然后它必须尝试做出服务决定

/gamecenter/

或者

/gamecenter/gamecenter/../ (Because in terms of folder structure the alias name is 1 folder level down in the web than it is physically)

最终会感到困惑,任何虚拟主机设置在无法解析路径时所做的事情也是如此,那就是返回网站根目录。

然而,正如我所说,这是一般的 NON-MONO Apache 行为,mod_mono 可能会以某种方式改变处理管道,从而可能会改变这种行为。

我建议将其拆分为 3 个虚拟主机,即使仅在一个 IP 上也可以非常轻松地完成。

您要做的第一件事是在您的主 Apache 配置文件中的某个位置,有一个

Listen 9005

陈述。这将使所有虚拟实例侦听该端口以及任何其他配置的端口 EG:80

接下来确保你有一个默认的捕获所有虚拟主机,这将捕获任何未映射到其他地方的服务器名称:

<VirtualHost *>
  DocumentRoot "/some/folder/where/the/default/is/"
  #Followed by other server directives. NOTE: there is NO servername line
</VirtualHost>

一旦你完成了设置,然后进入你的“api”子域

<VirtualHost *>
  ServerName api
  DocumentRoot "/Library/WebServer/vhosts/api/"
  #Other required directives here
</VirtualHost>

在这一点上,我将暂停讨论您的域名。如果这是一个内部测试系统(我怀疑它是),那么如果您在盒子上安装 DNS 服务器,然后使用私有内部网络地址将其设置为主域,您会发现虚拟域的生活会更容易。

例如:

创建一个根区域,并将其命名为“mydevnetwork.local”

然后向其中添加机器名称:

EG:如果您的电脑名为 devpc1,请为“devpc1.mydevnetwork.local”创建一个 IP 地址,并为您的电脑提供一个静态 IP 地址 EG:192.168.50.1

然后为此设置一个别名

api.mydevnetwork.local = devpc1.mydevnetwork.local

我没有足够的空间在这里做一个完整的 DNS 设置帖子,但希望你能明白。

一旦您设置了 DNS(或至少主机文件条目),那么您在 Apache 下的虚拟主机变得非常易于管理:

<VirtualHost *>
  ServerName api.mydevnetwork.local
  DocumentRoot "/Library/WebServer/vhosts/api/"
  #Other required directives here
</VirtualHost>

如果您也需要,也可以轻松迁移到另一台机器上。

您可以以几乎相同的方式设置其余的虚拟主机

<VirtualHost *>
  ServerName gamecenter.mydevnetwork.local
  DocumentRoot "/Library/WebServer/vhosts/api/gamecenter/"
  #Other required directives here
</VirtualHost>

<VirtualHost *>
  ServerName gamecenter-stage.mydevnetwork.local
  DocumentRoot "/Library/WebServer/vhosts/api/gamecenter-stage/"
  #Other required directives here
</VirtualHost>

注意 iv'e 将路径设置为与上面的相同,即使这样可行,我强烈建议您为每个人提供自己独特的文件夹,我通常会执行以下操作:

wwwroot
    api.mydevnetwork.local
        htdocs   <-- Web files go here
        cgi-bin  <-- cgi scripts go here and it's mapped to /cgi-bin/
        logs     <-- logs here
        access   <-- htpasswd files here

希望如果以上不是一个完整的解决方案,您至少可以从中获得一些进一步的调查想法。

于 2011-10-12T19:51:38.790 回答