如何使用Apache将子域转发到同一IP地址上的新端口? [英] How to forward a subdomain to a new port on the same IP address using Apache?
问题描述
我有一个24/7全天候运行的NAS/服务器,并在其上运行许多不同的服务.我现在有一个指向它的域名,想知道是否有可能创建指向不同服务端口的子域.例如:
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路由器,当前该端口将所有这些端口转发到IP为192.168.0.104的NAS/服务器.
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虚拟主机来处理此问题,因为这些子域将进入apache正在侦听的端口80?还是虚拟主机不能像这样工作?
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指南
Documentation:
- Guide to creating name-based virtual hosts
- Core, including VirtualHost and NameVirtualHost
- Redirect
- mod_rewrite guide
这篇关于如何使用Apache将子域转发到同一IP地址上的新端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!