如何使用 Apache 将子域转发到同一 IP 地址上的新端口? [英] How to forward a subdomain to a new port on the same IP address using Apache?
问题描述
我有一台 NAS/服务器 24/7 全天候在家运行,并在其上运行许多不同的服务.我现在有一个指向它的域名,并且想知道是否可以创建指向不同服务的不同端口的子域.例如:
I have a NAS/Server running at home 24/7 and run many different services on it. I have got a domain name pointing to it now, and was wondering if it would be possible to create sub-domains that point to different ports for different services. For example:
- http://subsonic.mydomain.com --> XXX.XXX.XXX.XXX:4040
- http://minecraft.mydomain.com --> XXX.XXX.XXX.XXX:25565
- http://files.mydomain.com --> XXX.XXX.XXX.XXX:4082
- http://subsonic.mydomain.com --> XXX.XXX.XXX.XXX:4040
- http://minecraft.mydomain.com --> XXX.XXX.XXX.XXX:25565
- http://files.mydomain.com --> XXX.XXX.XXX.XXX:4082
我有一个 D-LINK 路由器,它当前将所有这些端口转发到我的 NAS/服务器,其 IP 为 192.168.0.104.
I have a single D-LINK router that currently port forwards all these ports to my NAS/Server whose IP is 192.168.0.104.
服务器运行的是 Ubuntu 12.04.
The server is running Ubuntu 12.04.
我需要运行什么服务或代理才能识别子域并相应地路由流量?或者我可以使用 apache 虚拟主机来处理这个问题,因为这些子域将进入端口 80,哪个 apache 正在侦听?还是虚拟主机不是这样工作的?
What service or proxy do I need to run that can recognize the sub domain and route the traffic accordingly? Or could I use apache virtual hosts to handle this, because these subdomains will come in on port 80, which apache is listening to? Or does virtual hosts not work like this?
任何信息、想法或提示都会有所帮助/有用.
Any information, ideas, or tips would be helpful/useful.
推荐答案
有两种方法可以做到这一点.您可以使用 httpd.conf
的 VirtualHost 部分,也可以在 .htaccess
中进行.(假设子域解析为与您的网络服务器相同的 IP)
There are two ways to do this. You could use the VirtualHost section of your httpd.conf
or you could do it in your .htaccess
. (assuming that the subdomains resolve to the same IP as your webserver)
在httpd.conf
中:
<VirtualHost *:80>
ServerName subsonic.mydomain.com
redirect / http://mydomain.com:4040/
</VirtualHost>
在 .htaccess
中:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^subsonic\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com:4040/$1 [R=301]
文档:
- 创建基于名称的虚拟主机的指南
- 核心,包括VirtualHost 和 NameVirtualHost
- 重定向
- mod_rewrite 指南
这篇关于如何使用 Apache 将子域转发到同一 IP 地址上的新端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!