LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 02-11-2007, 03:57 PM   #1
sardaukar_siet
Member
 
Registered: Feb 2003
Location: London
Distribution: Fedora 22
Posts: 59

Rep: Reputation: 15
Question Single port open, multiple websites with Apache


Hello.

I have searched threads and couldn't find my question answered.

It's like this : I would like to have multiple websites with just one port open, and I know one can employ virtual hosts but I don't want to point to directories, but other servers running on localhost. So, if I have mldonkey serving on local port 6060 and SABnzbd on port 7221, I would like to have :

mldonkey.my_site.com -> redirects to -> localhost:6060
sabnzbd.my_site.com -> redirects to -> localhost:7221
www.my_site.com -> normal website

I have found something similar, but this is to have Apache redirect content from a specific port (443) :
Code:
<~VirtualHost myhostname:443>

   ~RewriteEngine on
   ~RewriteRule /mldonkey/(.*) ~http://admin@myhostname:4080/$1 ~[[P,L]]
   ~RewriteRule /mldonkey/(submit.*) ~http://admin@myhostname:4080/$1 ~[[P,L]]
   ~RewriteRule /mldonkey/(files.*) ~http://admin@myhostname:4080/$1 ~[[P,L]]

   ~ProxyPassReverse /mldonkey/(.*) ~http://myhostname:4080/$1

<Location /mldonkey/>
   Order allow,deny
   Allow from all
    ~AuthType Basic
    ~AuthName \"MLDonkey\"
    ~AuthUserFile /etc/apache2/keys.dat
    Require valid-user
</Location>
Is there a way to make this redirect work based on subdomain name?

Please help, and thanks in advance!
 
Old 02-11-2007, 04:42 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
basically you want mod_proxy and probably not anything else really...

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

you're looking at mod_rewrite there mainly which is generally a fairly scary thing, but mod_proxy is normally just a rule in one direction (mapping requested uri on apache server to remote resource) and the reverse of it for translating back.
 
Old 02-11-2007, 04:51 PM   #3
sardaukar_siet
Member
 
Registered: Feb 2003
Location: London
Distribution: Fedora 22
Posts: 59

Original Poster
Rep: Reputation: 15
I kinda have it working...

This works :

Code:
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName sab.my.domain.com

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://127.0.0.1:6060/
    ProxyPassReverse / http://127.0.0.1:6060/
    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>
But my main website (requests on my.domain.com) vanishes. This should work (right?) :

Code:
NameVirtualHost www.my.domain.com:80
<VirtualHost www.my.domain.com:80>
</VirtualHost>

NameVirtualHost my.domain.com:80
<VirtualHost my.domain.com:80>
</VirtualHost>

NameVirtualHost sab.my.domain.com:80
<VirtualHost sab.my.domain.com:80>
    ServerName sab.my.domain.com

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://127.0.0.1:6060/
    ProxyPassReverse / http://127.0.0.1:6060/
    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>
But I get [warn] NameVirtualHost sab.my.domain.com:80 has no VirtualHosts when I restart the Apache service and indeed does not work, since I get File does not exist: /var/www/html/sabnzbd on my logs when I access sab.my.domain.com.
What gives?

Last edited by sardaukar_siet; 02-11-2007 at 04:52 PM.
 
Old 02-11-2007, 05:08 PM   #4
sardaukar_siet
Member
 
Registered: Feb 2003
Location: London
Distribution: Fedora 22
Posts: 59

Original Poster
Rep: Reputation: 15
Success!

Code:
NameVirtualHost *:80
<VirtualHost *:80>
    ServerName www.my.domain.com
</VirtualHost>

<VirtualHost *:80>
    ServerName my.domain.com
</VirtualHost>

<VirtualHost *:80>
    ServerName sab.my.domain.com

    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://127.0.0.1:6060/
    ProxyPassReverse / http://127.0.0.1:6060/
    <Location />
        Order allow,deny
        Allow from all
    </Location>
</VirtualHost>
It works now!

What are the security implications of using this? Any possibility of proxying through my server?

Last edited by sardaukar_siet; 02-11-2007 at 05:09 PM.
 
Old 02-12-2007, 03:04 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
no, nothing risky really, nothing that doesn't already exist in the servicers you're running.
 
  


Reply

Tags
apache, hosts, proxypass, virtual



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache - running multiple websites on one host xtra Linux - General 5 06-30-2010 04:51 AM
Connecting a single ethernet port to multiple PCs? beejayzed Linux - Networking 14 09-08-2005 04:14 PM
multiple ssl certs, single apache server? hank43 Linux - Software 0 01-26-2005 04:56 PM
How to configure multiple websites on one PC? <Ol>Origy Linux - Networking 8 08-16-2004 07:16 AM
How-to setup on Apache some Multiple Namebased Virtual Websites with cgi-bin FunkFlex Linux - Newbie 0 02-08-2002 08:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration