Friday, March 17, 2017

tomcat - Apache UseCanonicalName On isnt passing ServerName to CGI

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?

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...