如何在运行 Apache2 的单个虚拟主机上托管多个 MVC3 站点? [英] How do I host multiple MVC3 sites on a single virtual host running Apache2?

查看:16
本文介绍了如何在运行 Apache2 的单个虚拟主机上托管多个 MVC3 站点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to configure mod_mono with Apache2 on OSX. I would like to run multiple MVC3 projects on the same virtual host, but for some reason only the first one listed is working. Any help on this would be much appreciated as there is not much documentation on this. I've tried a lot of different config options, none of which seem to work.

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>

推荐答案

你的问题是你的Alias name和物理路径是一回事,所以apache不知道服务哪一个.

your problem is that your Alias name and physical path are one and the same, so apache doesn't know which one to serve up.

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

NOTE: I'm giving the answer based on general Apache2 configuration, and not on mod_mono, maybe mod_mono does something to prevent this, I've not set MVC apps up under a *nix box before :-)

无论如何...

如果您查看您的路径配置...

if you look at your path configurations you have...

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

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

without your aliases in place, these already resolve to the paths your trying to map.

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

然后你告诉 Apache

Your then telling Apache that

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

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

When Apache tries to deliver the content if there is no file subfix or existing slash (as in the last 2) it will automatically, subfix the folder with a / then issue a redirect (306 I believe) essentially telling the browser to redirect from EG:

/gamecenter to /gamecenter/

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

With the alias in place to tell it that Alias ... is at location x it then has to try and make a desicion to serve

/gamecenter/

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

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

and ends up getting confused, and so does what any virtual host set up does when it's unable to resolve the path, and that's return the website root.

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

AS I SAY however, this is general NON-MONO Apache behaviour, it is possible that mod_mono may alter the processing pipeline in some way to that may change this behaviour.

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

What I would recommend is to split this into 3 virtual hosts which you can do very very easily even on just one IP.

你要做的第一件事是在你的主 Apache 配置文件的某个地方,有一个

First thing you'll want to do is somwhere in your master Apache config file, have a

Listen 9005

声明.这将使所有虚拟实例在该端口以及任何其他配置的端口 EG 上侦听:80

statement. This will make ALL virtual instances listen on that port as well as any other configured port EG: 80

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

Next make sure you have a default catch all virtual host, this will catch any server name not mapped elsewhere:

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

设置完成后,进入api"子域

Once you have that set up, then move onto your "api" sub domain

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

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

At this point, I'm going to pause to discuss your domain name. If this is an internal test system (Which I suspect it is) then you'll find life with virtual domains way easier if you install a DNS server on you box, then set that up as a master domain using a private internal network address.

EG:

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

Create a root zone, and call it "mydevnetwork.local"

然后添加机器名称:

EG:如果你的电脑叫devpc1,为devpc1.mydevnetwork.local"创建一个IP地址,并给你的电脑一个静态IP地址EG:192.168.50.1

EG: if your pc is called devpc1, create an IP address for "devpc1.mydevnetwork.local" and give your pc a static IP address of EG: 192.168.50.1

然后为它设置一个别名

api.mydevnetwork.local = devpc1.mydevnetwork.local

api.mydevnetwork.local = devpc1.mydevnetwork.local

我没有足够的空间在此处发布完整的 DNS 设置帖子,但希望您能理解.

Iv'e not got the room to do a full DNS setup post here, but hopefully you get the idea.

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

Once you have DNS (or at a minimum host file entries) set up, then your virtual hosts under Apache become really easy to manage:

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

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

and easy to relocate to another machine should you need too.

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

You can set the rest of your virtual hosts up in much the same way

<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>

请注意,我将路径设置为与上面的相同,即使这会起作用,我强烈建议您为每个人提供自己独特的文件夹,我通常会这样做:

Note iv'e set the paths to be the same as you had above, and even though this will work, I'd strongly advise that you give each one it's own unique folder, I generally do something like:

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

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

Hopefully if the above is not a complete solution, you might at least get some further ideas of investigation from it.

这篇关于如何在运行 Apache2 的单个虚拟主机上托管多个 MVC3 站点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆