How to forward a subdomain to a new port on the same IP address using Apache? [closed]

回眸只為那壹抹淺笑 提交于 2019-11-30 10:41:09

问题


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

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.

EDIT: The server is running Ubuntu 12.04.

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.


回答1:


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)

In httpd.conf:

<VirtualHost *:80>
    ServerName subsonic.mydomain.com
    redirect / http://mydomain.com:4040/
</VirtualHost>

In .htaccess:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subsonic\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com:4040/$1 [R=301]

Documentation:
- Guide to creating name-based virtual hosts
- Core, including VirtualHost and NameVirtualHost
- Redirect
- mod_rewrite guide



来源:https://stackoverflow.com/questions/12715195/how-to-forward-a-subdomain-to-a-new-port-on-the-same-ip-address-using-apache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!