apache windows2003上的Apache和IIS并排(都侦听端口80)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/108387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache and IIS side by side (both listening to port 80) on windows2003
提问by Dane O'Connor
What are some good ways to do this? Is it even possible to do cleanly?
有什么好的方法可以做到这一点?甚至有可能做到干净吗?
Ideally I'd like to use packet headers to decide which server should handle requests. However, if there is an easier/better way let me know.
理想情况下,我想使用数据包头来决定哪个服务器应该处理请求。但是,如果有更简单/更好的方法,请告诉我。
采纳答案by mdb
It's impossible for both servers to listen on the same port at the same IP address: since a single socket can only be opened by a single process, only the first server configured for a certain IP/port combination will successfully bind, and the second one will fail.
两台服务器不可能在同一个 IP 地址上监听同一个端口:由于单个套接字只能由单个进程打开,因此只有为特定 IP/端口组合配置的第一个服务器才能成功绑定,第二个服务器将成功绑定将失败。
You will thus need a workaround to achieve what you want. Easiest is probably to run Apache on your primary IP/port combination, and have it route requests for IIS (which should be configured for a different IP and/or port) to it using mod_rewrite.
因此,您将需要一种解决方法来实现您想要的。最简单的方法可能是在您的主要 IP/端口组合上运行 Apache,并使用mod_rewrite将 IIS(应针对不同的 IP 和/或端口进行配置)的请求路由到它。
Keep in mind that the alternative IP and port IIS runs on should be reachable to the clients connecting to your server: if you only have a single IP address available, you should take care to pick an IIS port that isn't generally blocked by firewalls (8080 might be a good option, or 443, even though you're running regular HTTP and not SSL)
请记住,连接到服务器的客户端应该可以访问 IIS 运行的备用 IP 和端口:如果您只有一个可用的 IP 地址,则应注意选择通常不会被防火墙阻止的 IIS 端口(8080 可能是一个不错的选择,或者 443,即使您运行的是常规 HTTP 而不是 SSL)
P.S. Also, please note that you do need to modify the IIS default configuration using httpcfg before it will allow other servers to run on port 80 on any IP address on the same server: see Micky McQuade's answer for the procedure to do that...
PS 另外,请注意,您确实需要使用 httpcfg 修改 IIS 默认配置,然后才能允许其他服务器在同一服务器上的任何 IP 地址上的端口 80 上运行:请参阅 Micky McQuade 的回答以了解执行此操作的过程...
回答by Micky McQuade
I found this postwhich suggested to have two separate IP addresses so that both could listen on port 80.
我发现这篇文章建议有两个单独的 IP 地址,以便两者都可以侦听端口 80。
There was a caveat that you had to make a change in IIS because of socket pooling. Here are the instructions based on the link above:
有一个警告,由于套接字池,您必须在 IIS 中进行更改。以下是基于上述链接的说明:
- Extract the
httpcfg.exeutility from the support tools area on the Win2003 CD. - Stop all IIS services:
net stop http /y - Have IIS listen only on the IP address I'd designated for IIS:
httpcfg set iplisten -i 192.168.1.253 - Make sure:
httpcfg query iplisten(The IPs listed are the only IP addresses that IIS will be listening on and no other.) - Restart IIS Services:
net start w3svc - Start the Apache service
httpcfg.exe从 Win2003 CD 上的支持工具区域中提取该实用程序。- 停止所有 IIS 服务:
net stop http /y - 让 IIS 只监听我为 IIS 指定的 IP 地址:
httpcfg set iplisten -i 192.168.1.253 - 请确保:(
httpcfg query iplisten列出的 IP 是 IIS 将侦听的唯一 IP 地址,没有其他 IP 地址。) - 重新启动 IIS 服务:
net start w3svc - 启动Apache服务
回答by Walf
For people with only one IP addressand multiple siteson one server, you can configure IIS to listen on a port other than 80, e.g 8080by setting the TCP port in the properties of each of its sites (including the default one).
对于在一台服务器上只有一个 IP 地址和多个站点的人,您可以将 IIS 配置为侦听除 之外的端口80,例如8080通过在其每个站点(包括默认站点)的属性中设置 TCP 端口。
In Apache, enable mod_proxyand mod_proxy_http, then add a catch-all VirtualHost (after all others) so that requests Apache isn't explicitly handling get "forwarded" on to IIS.
在 Apache 中,启用mod_proxy和mod_proxy_http,然后添加一个包罗万象的 VirtualHost(在所有其他人之后),以便 Apache 未明确处理的请求被“转发”到 IIS。
<VirtualHost *:80>
ServerName foo.bar
ServerAlias *
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8080/
</VirtualHost>
Now you can have Apache serve some sites and IIS serve others, with no visible difference to the user.
现在,您可以让 Apache 为某些站点提供服务,而让 IIS 为其他站点提供服务,而对用户没有明显的区别。
Edit:your IIS sites must not include their port number in any URLs within their responses, including headers.
编辑:您的 IIS 站点不得在其响应中的任何 URL 中包含其端口号,包括标头。
回答by Walf
You need at least mod_proxy and mod_proxy_http which both are part of the distribution (yet not everytime built automatically). Then you can look here: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
您至少需要 mod_proxy 和 mod_proxy_http 它们都是发行版的一部分(但并非每次都自动构建)。然后你可以看这里:http: //httpd.apache.org/docs/2.2/mod/mod_proxy.html
Simplest config in a virtualhost context is:
虚拟主机上下文中最简单的配置是:
ProxyPass /winapp http://127.0.0.1:8080/somedir/
ProxyPassReverse /winapp http://127.0.0.1:8080/somedir/
(Depending on your webapp, the actual config might become more sophisticated. ) That transparently redirects every request on the path winapp/ to the windows server and transfers the resulting output back to the client.
(根据您的 web 应用程序,实际配置可能会变得更加复杂。)这透明地将路径 winapp/ 上的每个请求重定向到 Windows 服务器并将结果输出传输回客户端。
Attention: Take care of the links in the delivered pages: they aren't rewritten, so you can save yourself lotsa hassle if you generally use relative links in your app, like
注意:注意交付页面中的链接:它们不会被重写,因此如果您通常在应用程序中使用相对链接,则可以省去很多麻烦,例如
<a href=../pics/mypic.jpg">
instead of the usual integration nightmare of every link being absolute:
而不是每个链接都是绝对的通常的集成噩梦:
<a href="http://myinternalhostname/somedir/crappydesign.jpg">
THE LATTER IS BAD ALMOST EVERY SINGLE TIME!
后者几乎每一次都很糟糕!
For rewriting links in pages there's mod_proxy_html (not to confuse with mod_proxy_http!) but that's another story and a cruel one as well.
对于重写页面中的链接,有 mod_proxy_html(不要与 mod_proxy_http 混淆!)但这是另一个故事,也是一个残酷的故事。
回答by Walf
Either two different IP addresses (like recommended) or one web server is reverse-proxying the other (which is listening on a port <>80).
两个不同的 IP 地址(如推荐的)或一个 Web 服务器正在反向代理另一个(正在侦听端口 <> 80)。
For instance: Apache listens on port 80, IIS on port 8080. Every http request goes to Apache first (of course). You can then decide to forward every request to a particular (named virtual) domain or every request that contains a particular directory (e.g. http://www.example.com/winapp/) to the IIS.
例如:Apache 在端口 80 上侦听,IIS 在端口 8080 上侦听。每个 http 请求首先转到 Apache(当然)。然后,您可以决定将每个请求转发到特定(命名虚拟)域或包含特定目录(例如http://www.example.com/winapp/)的每个请求转发到 IIS。
Advantage of this concept is that you have only one server listening to the public instead of two, you are more flexible as with two distinct servers.
这个概念的优点是你只有一个服务器而不是两个监听公共广播,你可以更灵活地使用两个不同的服务器。
Drawbacks: some webapps are crappily designed and a real pain in the ass to integrate into a reverse-proxy infrastructure. A working IIS webapp is dependent on a working Apache, so we have some inter-dependencies.
缺点:一些 web 应用程序的设计很糟糕,集成到反向代理基础设施中真的很麻烦。一个有效的 IIS webapp 依赖于一个有效的 Apache,所以我们有一些相互依赖。
回答by Matthew White
I see this is quite an old post, but came across this looking for an answer for this problem. After reading some of the answers they seem very long winded, so after about 5 mins I managed to solve the problem very simply as follows:
我看到这是一个很老的帖子,但是遇到了这个寻找这个问题的答案。在阅读了一些答案后,他们似乎很啰嗦,所以大约 5 分钟后,我设法非常简单地解决了这个问题,如下所示:
httpd.conf for Apache leave the listen port as 80 and 'Server Name' as FQDN/IP :80.
Apache 的 httpd.conf 将监听端口保留为 80,将“服务器名称”保留为 FQDN/IP :80。
Now for IIS go to Administrative Services > IIS Manager > 'Sites' in the Left hand nav drop down > in the right window select the top line (default web site) then bindings on the right.
现在对于 IIS,转到管理服务 > IIS 管理器 > 左侧导航下拉菜单中的“站点” > 在右侧窗口中选择顶行(默认网站),然后选择右侧的绑定。
Now select http > edit and change to 81 and enter your local IP for the server/pc and in domain enter either your FQDN (www.domain.com) or external IP close.
现在选择 http > edit 并更改为 81 并输入服务器/PC 的本地 IP,并在域中输入您的 FQDN (www.domain.com) 或外部 IP 关闭。
Restart both servers ensure your ports are open on both router and firewall, done.
重启两台服务器,确保你的端口在路由器和防火墙上都打开,完成。
This sounds long winded but literally took 5 mins of playing about. works perfectly.
这听起来很啰嗦,但实际上花了 5 分钟的时间。完美运行。
System: Windows 8, IIS 8, Apache 2.2
系统:Windows 8、IIS 8、Apache 2.2
回答by Riccardo Siccardi
Installing Windows 10 I had this problem: apache(ipv4) and spooler service(ipv6) listening the same 80 port.
安装 Windows 10 我遇到了这个问题:apache(ipv4) 和假脱机服务(ipv6) 监听同一个 80 端口。
I resolved editing apache httpd.conf file changing the line
我解决了编辑 apache httpd.conf 文件更改行的问题
Listen 80
听 80
to
到
Listen 127.0.0.1:80
听 127.0.0.1:80
回答by Andre Kaufmann
That's not quite true. E.g. for HTTP Windows supports URL based port sharing, allowing multiple processes to use the same IP address and Port.
这并不完全正确。例如对于 HTTP Windows 支持基于 URL 的端口共享,允许多个进程使用相同的 IP 地址和端口。
回答by stephenbayer
You will need to use different IP addresses. The server, whether Apache or IIS, grabs the traffic based on the IP and Port, which ever they are bound to listen to. Once it starts listening, then it uses the headers, such as the server name to filter and determine what site is being accessed. You can't do it will simply changing the server name in the request
您将需要使用不同的 IP 地址。服务器,无论是 Apache 还是 IIS,都会根据 IP 和端口获取流量,无论它们必须侦听哪一个。一旦开始侦听,它就会使用标头(例如服务器名称)来过滤和确定正在访问的站点。你不能这样做只会改变请求中的服务器名称

