我怎么主机上运行的Apache2一台虚拟主机上的多个网站MVC3? [英] How do I host multiple MVC3 sites on a single virtual host running Apache2?
问题描述
我想用的Apache2在OSX配置是mod_mono。我想在同一虚拟主机上运行多个MVC3项目,但由于某些原因仅列第一个工作。任何帮助将是非常美联社preciated因为没有太多的文档这一点。我已经尝试了很多不同的配置选项,其中没有一个似乎工作。
收听*:9005
<虚拟主机*:9005>
的DocumentRoot/库/ Web服务器/虚拟主机/ API
服务器名API
MonoAutoApplication禁用 别名/ GameCenter的/库/ Web服务器/虚拟主机/ API / GameCenter的
AddMonoApplications的GameCenter/ GameCenter的:/库/ Web服务器/虚拟主机/ API / GameCenter的
MonoServerPath的GameCenter的/ usr / bin中/ MOD-单服务器4
MonoDebug GameCenter的真
MonoSetEnv的GameCenter MONO_IOMAP =所有
MonoUnixSocket的GameCenter级的/ tmp / mod_mono_server_gc
<位置/ GameCenter的>
所有允许
为了允许,拒绝
MonoSetServerAlias的GameCenter
SetHandler单
SetOutputFilter DEFLATE
SetEnvIfNoCase REQUEST_URI\\。(?: GIF | JPE G |?PNG)$无gzip的不要,各不相同
< /地点> 别名/ GameCenter的阶段/库/ Web服务器/虚拟主机/ API / GameCenter的阶段
MonoServerPath GameCenter的阶段的/ usr / bin中/ MOD-单服务器4
MonoDebug的GameCenter级真
MonoSetEnv GameCenter的阶段MONO_IOMAP =所有
AddMonoApplications GameCenter的阶段/ GameCenter的阶段:/库/ Web服务器/虚拟主机/ API / GameCenter的阶段
MonoUnixSocket的GameCenter级的/ tmp / mod_mono_server_gcs
<位置/ GameCenter的阶段>
所有允许
为了允许,拒绝
MonoSetServerAlias GameCenter的阶段
SetHandler单
SetOutputFilter DEFLATE
SetEnvIfNoCase REQUEST_URI\\。(?: GIF | JPE G |?PNG)$无gzip的不要,各不相同
< /地点> < IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text / html的文本/纯文本/ XML文本/ JavaScript的
< / IfModule>
< /虚拟主机>
你的问题是,你的别名和物理路径是同一个,因此Apache不知道来提供哪一个。
请注意:我根据一般的Apache2配置给了答案,而不是将mod_mono,也许是mod_mono做一些事情,以prevent这一点,我没有设定MVC :-)前已根据* nix中框Apps设定
反正...
如果你看看你的路径配置你有...
/库/ Web服务器/虚拟主机/ API
/库/ Web服务器/虚拟主机/ API / GameCenter的
/库/ Web服务器/虚拟主机/ API / GameCenter的阶段
不到位你的别名,这些已经解决您试图映射的路径。
/库/ Web服务器/虚拟主机/ API = /
/库/ Web服务器/虚拟主机/ API / GameCenter的= / GameCenter的
/库/ Web服务器/虚拟主机/ API / GameCenter的阶段= / GameCenter的阶段
您再告诉阿帕奇的
/ = /
/ GameCenter的= / GameCenter的
/ GameCenter的阶段= / GameCenter的阶段
在Apache的尝试,如果没有文件subfix或现有的斜杠(如在最后2)为客户提供的内容会自动,subfix文件夹用/然后发出一个重定向(306我相信)实质上是告诉浏览器从EG重定向:
/ GameCenter的来/ GameCenter的/
使用到位,告诉它的别名别名......是位置x它,然后有尝试做一个desicion服务
/ GameCenter的/
或
/ GameCenter的/ GameCenter的/../(由于文件夹结构方面的别名为1文件夹级别倒在网上比它身体上)
和结束感到困惑,所以做什么的虚拟主机设置确实当它无法解析路径,这就是返回网站根目录。
然而,正如我所说,这是一般的非MONO的Apache行为,它有可能是mod_mono可能会改变以某种方式可能会改变这种行为的处理管道。
我会建议是把它们分割,你甚至可以只在一个IP做的非常非常容易地3虚拟主机。
你会想要做的第一件事是在somwhere你的主人Apache的配置文件,有一个
收听9005
声明。这将使所有的虚拟实例侦听端口,以及任何其他配置的端口上EG:80
下一步要确保你有一个默认的包罗万象的虚拟主机,这将捕获任何服务器名称不是别处映射:
<虚拟主机* GT;
的DocumentRoot/部分/文件夹/在哪里/的/缺省的/是/
其他服务器的指令#Followed。注:没有服务器名行
< /虚拟主机>
一旦你的设置,然后移动到你的API子域
<虚拟主机* GT;
服务器名API
的DocumentRoot/库/ Web服务器/虚拟主机/ API /
这里需要#Other指令
< /虚拟主机>
在这一点上,我要停下来讨论你的域名。如果这是一个内部测试系统(我怀疑它是)那么你会发现生活与虚拟域的方式更容易,如果你在你机器上安装DNS服务器,然后设置了为使用专用的内部网络地址的主域。
例如:
创建根区,并称之为mydevnetwork.local
然后计算机名称添加到它:
例如:如果你的电脑被称为devpc1,创建devpc1.mydevnetwork.local一个IP地址,让您的电脑EG的静态IP地址:192.168.50.1
然后设置一个别名,这么
api.mydevnetwork.local = devpc1.mydevnetwork.local
Iv'e没有得到房间在这里做一个完整的DNS设置岗位,但希望你的想法。
一旦你有了DNS(或至少主机文件项)成立,那么Apache下你的虚拟主机变得非常易于管理:
<虚拟主机* GT;
服务器名api.mydevnetwork.local
的DocumentRoot/库/ Web服务器/虚拟主机/ API /
这里需要#Other指令
< /虚拟主机>
和易于搬迁到另一台机器如果您需要了。
您可以设置您的虚拟主机的其余起来大致相同的方式
<虚拟主机* GT;
服务器名gamecenter.mydevnetwork.local
的DocumentRoot/库/ Web服务器/虚拟主机/ API / GameCenter的/
这里需要#Other指令
< /虚拟主机><虚拟主机* GT;
服务器名称的GameCenter,stage.mydevnetwork.local
的DocumentRoot/库/ Web服务器/虚拟主机/ API / GameCenter的阶段/
这里需要#Other指令
< /虚拟主机>
请注意iv'e设置的路径是一样的,你上面有,即使这会工作,我强烈建议你给每一个它自己独特的文件夹,我一般是这样的:
wwwroot文件
api.mydevnetwork.local
htdocs目录< - 网页文件放在这里
cgi-bin目录下&; - CGI脚本放在这里,它的映射/ cgi-bin目录/
日志< - 在这里记录
访问< - 在这里的htpasswd文件
希望如果上面没有一个完整的解决方案,你可能至少得到调查的一些想法进一步从它。
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>
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.
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 :-)
Anyway...
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
Your then telling Apache that
/ = /
/gamecenter = /gamecenter
/gamecenter-stage = /gamecenter-stage
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/
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/
or
/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.
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.
What I would recommend is to split this into 3 virtual hosts which you can do very very easily even on just one IP.
First thing you'll want to do is somwhere in your master Apache config file, have a
Listen 9005
statement. This will make ALL virtual instances listen on that port as well as any other configured port EG: 80
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>
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>
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:
Create a root zone, and call it "mydevnetwork.local"
then add machine names to it:
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
Then set an alias for that so
api.mydevnetwork.local = devpc1.mydevnetwork.local
Iv'e not got the room to do a full DNS setup post here, but hopefully you get the idea.
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屋!