NullVoxPopuli
NullVoxPopuli

Reputation: 65123

How do you use apache to route different subdomains to different ports / servers?

On my dev machine, I want to be able to have an SSL server, and a non-SSL server (both running off the same code... but running both servers is the easy part.)

For my regular server: I want it to be sub1.mydomain.com

so, I've modified my VirtualHost such that instead of saying

mydomain.com
*.mydomain.com,

it says

sub1.mydomain.com
*.sub1.mydomain.com

and then for the SSL server, I just said

sub2.mydomain.com
*.sub2.mydomain.com

except, whenever I got to a sub2.mydomain url, the server attached to sub1 processes the request.

What am I doing wrong here?

I'm using ruby on rails, and apache.

EDIT: added the actual virtual hosts

<VirtualHost *:80>
    DocumentRoot "/Users/me/projects/myproject/public"
    ServerName reg.mydomain.com
    #ServerAlias *.reg.mydomain.com
    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001
</VirtualHost>


<VirtualHost *:443>
    SSLEngine on
    SSLProxyEngine On
    RequestHeader set Front-End-Https "On"
    CacheDisable *
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    DocumentRoot "/Users/me/projects/myproject/public"
    ServerName ssl.mydomain.com
    #ServerAlias *.ssl.mydomain.com
    SSLCertificateKeyFile "/private/etc/apache2/certs/server.key"
    SSLCertificateFile "/private/etc/apache2/certs/server.crt"

    ProxyPass / https://localhost:3002/
    ProxyPassReverse / https://localhost:3002
    ProxyPreserveHost on    
</VirtualHost>

Upvotes: 1

Views: 2722

Answers (1)

Nick Martin
Nick Martin

Reputation: 282

It sounds like you're trying to do named virtual hosts?

http://httpd.apache.org/docs/2.2/vhosts/name-based.html

Assuming that rails isn't doing anything too funky, you can try having a virtual host that looks like this:

NameVirtualHost *

<VirtualHost *>
ServerName sub1.mydomain.com
DocumentRoot /var/www/sub1 or point this to the server instead.
</VirtualHost>

<VirtualHost *>
ServerName sub2.mydomain.com
DocumentRoot /var/www/sub2 or point this to the server instead.
</VirtualHost>

Upvotes: 1

Related Questions