Html 创建一个指向非 80 端口 IP 的域名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25971399/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:45:04  来源:igfitidea点击:

create a domain name pointing to an IP of port different than 80

htmlapachehttpdnsip

提问by george

I would like to use a domain name to point to a web page on the local server's IP address. However, the problem is that the page is linked to an IP address set up on port 8088 rather than 80 because the latter is already used by another web page. By the domain company I was told that they cannot do it because the domain can only point to an IP address set up on port 80. So now I am in a deadlock. What alternatives do I have and how can I make a domain pointing to the IP:8088?

我想使用域名指向本地服务器IP地址上的网页。但是,问题是该页面链接到在端口 8088 而不是 80 上设置的 IP 地址,因为后者已被另一个网页使用。域公司告诉我他们不能这样做,因为域只能指向在端口 80 上设置的 IP 地址。所以现在我陷入了僵局。我有哪些替代方案,如何使域指向 IP:8088?

Thanks

谢谢

回答by Kenster

The domain company that you talked to may have done a poor job of explaining how domains work. Domain names don't refer to specific ports. They just refer to IP addresses. The client can look up a hostname to get the IP address which the client should connect to, but the client has to figure out the port without the help of DNS. Port 80 is just the default port for HTTP service.

您与之交谈的域公司可能在解释域的工作原理方面做得很差。域名不指特定端口。它们只是指 IP 地址。客户端可以查找主机名以获取客户端应连接到的 IP 地址,但客户端必须在没有 DNS 帮助的情况下找出端口。80 端口只是 HTTP 服务的默认端口。

You can certainly run a web server on port 8088 if you like. The port number would have to appear in the URL, e.g. http://somehost.example.com:8080/some/page. Clients would parse this and know to connect to port 8080 instead of the default port 80.

如果您愿意,您当然可以在端口 8088 上运行 Web 服务器。端口号必须出现在 URL 中,例如http://somehost.example.com:8080/some/page. 客户端会解析它并知道连接到端口 8080 而不是默认端口 80。

If you don't want URLs to contain the port number, then requests are going to go to the default port 80, and you have no choice but to make the web server running on port 80 handle these requests. HTTP/1.1 requests include the hostname which the client wants to contact, and modern web server programs are normally capable of serving completely different sets of content based on the hostname in the request. There are few ways todo what you need:

如果您不希望 URL 包含端口号,那么请求将转到默认端口 80,您别无选择,只能让运行在端口 80 上的 Web 服务器处理这些请求。HTTP/1.1 请求包括客户端想要联系的主机名,现代 Web 服务器程序通常能够根据请求中的主机名提供完全不同的内容集。有几种方法可以满足您的需求:

  1. Just configure the web server for port 80 to handle both sites. This will depend on what web server software you're using. Apache for example calls these "virtual hosts", and here is a set of examples. This is a typical solution, and some people run hundreds of sites on the same server this way.

  2. Run your two web servers as you planned. Set up the server for port 80 to be a reverse proxyfor the second website. The server would continue to serve content for the site it handles now. When it receives a request for the second site, it would relay the request to the server running on port 8088, and relay the server's response back to the client.

  3. Move the existing server for port 80 to a different port. Run a pure reverse proxy server on port 80, relaying requests for both web sites to their respective web servers.

  1. 只需将 Web 服务器配置为端口 80 即可处理这两个站点。这将取决于您使用的 Web 服务器软件。例如,Apache 将这些称为“虚拟主机”,这里有一组示例。这是一个典型的解决方案,有些人以这种方式在同一台服务器上运行数百个站点。

  2. 按照您的计划运行您的两个 Web 服务器。将服务器的 80 端口设置为第二个网站的反向代理。服务器将继续为它现在处理的站点提供内容。当它收到对第二个站点的请求时,它会将请求中继到运行在端口 8088 上的服务器,并将服务器的响应中继回客户端。

  3. 将端口 80 的现有服务器移动到其他端口。在端口 80 上运行纯反向代理服务器,将两个网站的请求中继到各自的 Web 服务器。

You might be better off taking further questions to https://webmasters.stackexchange.com/or https://serverfault.com/.

您最好向https://webmasters.stackexchange.com/https://serverfault.com/提出更多问题。

回答by Cristian Oliveira

You can use a Proxy to reroute the given domain to the IP:PORT. To accomplish this you could either spin up a Nginx server and configure it as your reverse proxy or use this project that does exactly what you want and with almost no config https://github.com/cristianoliveira/ergo

您可以使用代理将给定域重新路由到 IP:PORT。要做到这一点,您可以启动 Nginx 服务器并将其配置为您的反向代理,或者使用该项目完全满足您的需求并且几乎没有配置https://github.com/cristianoliveira/ergo

回答by GarryOne

If you run Apache on port 80, which is the most common case then the easiest way to solve this issue is to set a VirtualHost that uses ProxyPass.

如果您在端口 80 上运行 Apache,这是最常见的情况,那么解决此问题的最简单方法是设置使用 ProxyPass 的 VirtualHost。

<VirtualHost sub.domain.com:80>   
  ProxyPass / https://ip-or-domain.com:8088/ 
</VirtualHost>