Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

On Apache 2.4 in in a virtualhost I have:

UseCanonicalName On
ServerName somename
ServerAlias www.someothername.com

According to the docs:

With UseCanonicalName On Apache will use the hostname and port specified in the ServerName directive to construct the canonical name for the server. This name is used in all self-referential URLs, and for the values of SERVER_NAME and SERVER_PORT in CGIs.

So in my Tomcat/CFML application when I visit the URL www.someothername.com I would expect to see in the CGI scope:

server_name: somename

but instead I get:

server_name: www.someothername.com

It's like the directive is totally ignored.

# Proxy CFML files to Tomcat
RewriteCond %{REQUEST_FILENAME} /[^/:]+\.cfml*($|/)
RewriteRule (.*) ajp://%{HTTP_HOST}:8009$1 [P,L]

I also tried:

RewriteRule (.*) ajp://%{SERVER_NAME}:8009$1 [P,L]

and using mod_proxy instead of AJP:

RewriteRule (.*) http://%{SERVER_NAME}:8888$1 [P,L]

The last 2 cause a DNS lookup on somename but still returns www.someothername.com in the CGI.SERVER_NAME field

I should point out that the only reason I'm doing this is because I'm doing mass virtual-hosting with mod_cfml to automaticatically create tomcat contexts and I would like the context and application to use a short name derived from the vhost configuration. I guess I could just set a header (even rewrite the Host: header) but using ServerName seemed the most elegant solution.

UPDATE: There is something I noticed in the client headers that is probably relevant. There are 2 headers I haven't seen before:

x-forwarded-host: www.someothername.com
x-forwarded-server: somename

I need to know what set these headers and why. I'm assuming it was either Tomcat or mod_cfml. Can I rely on the x-forwarded-server value to always be ServerName?

share|improve this question

1 Answer 1

You're not calling a CGI, you're proxying, so trying to set SERVER_NAME is either useless or very close to it.

Typically with mass virtual hosting you should use the actual domain name that you received, which is HTTP_HOST, the Host: HTTP header, in your application to make the distinction.

share|improve this answer
    
That makes some sense except that CFML engines DO emulate CGI and provide a CGI scope containing the fields you would expect. For point 2 I do not want seperate "contexts" based on the FQDN used by the client. What I want is many FQDN aliases all pointing to the same "shortname" context. I do want to preserve the 'Host' header information but I need the "true" ServerName as well. –  SpliFF Feb 3 at 4:31
    
Hmm. You'll have to get it elsewhere, then, I think. Perhaps that mysterious header you mentioned? It should only take a moment to test whether that behaves the way you expect. –  Michael Hampton Feb 3 at 4:32
    
Thanks but I think you're too quick to assume the original server_name value isn't being passed through because this is "not CGI". I don't think that's the issue at all. I think it is being overwritten at some point in the httpd -> mod_proxy -> mod_cfml -> tomcat -> railo processing chain and I can probably prevent that if I knew where. –  SpliFF Feb 3 at 4:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.