简体   繁体   English

根据请求URL重定向到不同的端口

[英]Redirect to different ports based on request URL

I'm using Windows Server 2003 . 我正在使用Windows Server 2003 I have one web application running on IIS and another web application running on Apache Tomcat . 我有一个在IIS上运行的Web应用程序,另一个在Apache Tomcat上运行的Web应用程序。 Currently all requests go to port 80 . 当前,所有请求都转到端口80 From what I understand, Tomcat and IIS cannot use the same port simultaneously. 据我了解,Tomcat和IIS无法同时使用同一端口。 Therefore I need a way to redirect users. 因此,我需要一种重定向用户的方法。 If a user goes to www.example.com then I need them to use http://localhost:80 but if they go to www.otherExample.com then I need them to use http://localhost:8084/otherExample 如果用户访问www.example.com,则我需要他们使用http://localhost:80但是如果他们访问www.otherExample.com,则我需要他们使用http://localhost:8084/otherExample

How does this generally get done? 通常如何完成?

  1. Set IIS to port 80. 将IIS设置为端口80。
  2. Create two virtual hosts on IIS for your two domains. 在IIS上为您的两个域创建两个虚拟主机。
  3. Set the document root of the first to a directory on your IIS. 将第一个文档的根目录设置为IIS上的目录。
  4. Remove the coyote http/1 connector from Tomcat. 从Tomcat移除土狼http / 1连接器。
  5. Look here , how to redirect from your IIS to Tomcat. 这里 ,如何从您的IIS重定向到Tomcat。
  6. Map the second virtual host to Tomcat according to the tutorial. 根据教程将第二个虚拟主机映射到Tomcat。

Then you can access example.com and otherExample.com without ports or directory changes. 然后,您可以访问example.com和otherExample.com,而无需更改端口或目录。

Well, you should go with something like this: 好吧,你应该这样:

First of all, I will assume that you know how to map example.com and otherexample.com to 127.0.0.1 and that is really what you want. 首先,我假设您知道如何将example.comotherexample.com映射到127.0.0.1 ,这确实是您想要的。 So I will skip that part and go straight to configuration. 因此,我将跳过这一部分,直接进行配置。

First of all, when users type http://www.domain.com it is EXACTLY THE SAME as typing http://www.domain.com:80 . 首先,当用户键入http://www.domain.com时 ,与键入http://www.domain.com:80 完全相同 Also, when users type https://www.domain.com it is EXACTLY THE SAME as typing https://www.domain.com:443 . 另外,当用户键入https://www.domain.com时 ,与键入https://www.domain.com:443 完全相同 That means, if you omit the ports for https and https, 80 and 443 are assumed respectively. 这意味着,如果省略https和https的端口,则分别假定80和443。

So, this brings you to only one conclusion. 因此,这仅使您得出一个结论。 You have to set one web server (IIS or Tomcat) to port 80, and another to port 8084. You decide which is which, because for configuration it is irrelevant. 您必须将一个Web服务器(IIS或Tomcat)设置为端口80,将另一个Web服务器设置为端口8084。您可以确定哪个服务器,因为与配置无关。

Now, to accomplish what you need, you need to create a redirection script on the server which listens to port 80 . 现在,要完成您需要的操作,您需要在侦听端口80的服务器上创建重定向脚本。 So, if you use PHP for redirection script, you could use something like this: 因此,如果将PHP用于重定向脚本,则可以使用如下所示的内容:

<?php

  if ($_SERVER['HTTP_HOST']=='www.otherexample.com') {
    Header('Location: http://localhost:8084/otherExample');
  }

?>

Also, you could accomplish something similar using configuration file of the server itself (the one that is listening on port 80). 同样,您可以使用服务器本身的配置文件(正在侦听端口80的配置文件)完成类似的操作。

This is only general explanation of the steps you need to take. 这仅是您需要采取的步骤的一般说明。 Obviously, you will need to adapt them to work for your case. 显然,您需要调整它们以适合您的情况。

Let me know what you think. 让我知道你的想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM