0

I have an apache server that lives behind a load balancer/proxy thing, within a k8s pod/container

At my main httpd.conf we have

ServerName my.site.example.com

(I have also tried my.site.example.com:443)

When you connect via https://my.site.example.com you will get to my page -- but the service in the container is actually listening on 8443. So we have

ServerName my.site.example.com # Or my.site.example.com:443, doesn't seem to matter <VirtualHost *:8443> Include redirects.conf </VirtualHost> 

Within redirects I have something like

RewriteRule ^/foo/bar$ /bang/quux [R=301,L] 

This kind of works except for apache will return a 301 for my.site.example.com:8443

Naturally that's a problem. After searching the documentation and trying a multitude of different approaches, it wasn't until I did

<VirtualHost *:8443> ServerName my.site.example.com:443 Include redirects.conf </VirtualHost> 

That it stopped adding :8443. UseCanonicalName and UseCanonicalPhysicalPort seemed to have zero effect without ServerName in the VirtualHost.

Our real config is quite large, so it's entirely possible that we have something else somewhere that is borking this up, but I haven't seen anything (grep -Inr ServerName config/path only returned the one global name, for instance) that leads me to believe that we have anything buggy.

I think that this is just how it's supposed to work but I don't understand based on Apache docs why.

So... am I doing something wrong here, or is it expected that I have to add ServerName to all of my VirtualHost entries?

1 Answer 1

2

is it expected that I have to add ServerName to all of my VirtualHost entries?

I would say yes – I think it makes a lot of sense that the global ServerName is not inherited by VirtualHosts, because the whole purpose of VirtualHost entries is to be accessible through a different name and/or different port. (And/or IP address, though that doesn't matter here.)

So from Apache httpd's point of view, it is a fairly unusual configuration for the same name:port to lead to several vhosts at once – and maybe you've really configured your reverse proxy that way (routing different URL paths to different Apache ports), but if you're doing unusual things then you have to be explicit about that.

Although the documentation for ServerName does not mention that it is not inherited from global scope, the name-based virtual host documentation does imply that: "If you omit the ServerName directive from any name-based virtual host, the server will default to a fully qualified domain name (FQDN) derived from the system hostname."

(As of Apache 2.4 all VirtualHosts are "name-based", if I remember correctly.)

And if the port were inherited, most users likely would be in the opposite situation from yours: e.g. personally I wouldn't expect at all that my <VirtualHost *:8443> vhost (i.e. where I had explicitly stated the port number) somehow inherited an overriding :443 specification from the "base" host.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.