6

I've got a name-based virtual host setup on port 443 such that requests on host 'apple.fruitdomain' are proxied to the apple-app and requests on host 'orange.fruitdomain' are proxied to orange-app. This is working, but I'd like to add a ServerAlias for each such that requests on host 'apple' are proxied to apple-app and requests on host 'orange' are proxied to the orange-app. If I simply add a ServerAlias directive to the virtual host it doesn't work. ssl.conf below:

Listen 443
NameVirtualHost *:443
<VirtualHost *:443>
ServerName apple.fruitdomain
ServerAlias apple
SSLProxyEngine on
ProxyPass /apple-app https://localhost:8181/apple-app
ProxyPassReverse /apple-app https://localhost:8181/apple-app
...
</VirtualHost>
<VirtualHost *:443>
ServerName orange.fruitdomain
ServerAlias orange
SSLProxyEngine on
ProxyPass /orange-app https://localhost:8181/orange-app
ProxyPassReverse /orange-app https://localhost:8181/orange-app
...
</VirtualHost>

Interestingly if I do a similar setup but with port 80 then the ServerAlias works...

7
  • 2
    What do you mean, "it doesn't work?"
    – cjc
    Apr 5, 2012 at 22:11
  • Does the orange name resolve to the correct address? What behavior are you seeing from your browser when you attempt to connect? Apr 6, 2012 at 1:59
  • When I say it doesn't work I mean the proxied app isn't found - the browser returns a 404 not found. I guess the virtual hosting match selection is what isn't working.
    – Ryan
    Apr 6, 2012 at 13:36
  • Note: the name resolution is working because if I navigate to the root using the short name 'orange' or 'apple' the root index comes up. If I add on the 'orange-app' or 'apple-app' part that is when I get 404.
    – Ryan
    Apr 6, 2012 at 13:58
  • @Ryan Can you check if the port 8181 listener is getting the proxied request and returning the 404 itself - does it log requests? Maybe set a quick Redirect directive up one of the fruits but not the other to check that the right vhost is being reached? Also, can you check and make sure there's nothing unexpected returned from apache2ctl -S? Apr 6, 2012 at 15:01

4 Answers 4

6

Well, from my testing it appears that the ServerAlias directive is ignored when using name-based virtual hosting on port 443 with Apache 2.2.15. This is probably due to the special SNI protocol requirement (SNI - Wikipedia; SNI - Apache Wiki). The work around is to create two separate virtual hosts; from my example one would have ServerName orange.fruitdomain and the other would have ServerName orange.

2
  • Any kind of name based virtual hosting using SSL will require SNI, not just hosts with multiple aliases. Suspect you haven't quite got the right answer here.
    – James Yale
    May 23, 2012 at 17:04
  • 1
    I think you misunderstood my answer. I'm not saying that only hosts with aliases require SNI. I'm saying that SNI is being used since I'm working with SSL (port 443) and this may explain why, all else being equal, the alias works for all other ports.
    – Ryan
    May 23, 2012 at 20:11
0

In order to fix underlined configuration you need to create another VirtualHost for "default" purposes using:

    ServerName localhost
or
    ServerName your_server_name

Please check apache httpd docs (Ex.) - http://httpd.apache.org/docs/2.2/mod/core.html#servername

The ServerName directive sets the request scheme, hostname and port that the server uses to identify itself. This is used when creating redirection URLs. Additionally, ServerName is used (possibly in conjunction with ServerAlias) to uniquely identify a virtual host, when using name-based virtual hosts.

-2

comment the listen 443 line because listening start with the ssl automaticaly and if you start it before it will see a conflict.

-7

http://wiki.apache.org/httpd/NameBasedSSLVHostsWithSNI

4
  • 3
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – user9517
    Apr 6, 2012 at 7:47
  • So inspite the answer is comprehensive and include problem analysis and problem solution, it's not preferrable? I'm confused.
    – Kondybas
    Apr 6, 2012 at 9:51
  • 2
    Far too many link only answers go dead. We really do prefer that answers contain content, not pointers to content. You can post a précis of the remote content for your answer and the link for clarification but not just a link.
    – user9517
    Apr 6, 2012 at 10:12
  • The linked document provided no clue as to why the ServerAlias isn't working. I've already got name-based virtual hosting on port 443 working in the simple case.
    – Ryan
    Apr 6, 2012 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .