0

I have an ubunutu server with apache2 server and I need to add a custom header to every request. This seems very straightforward, but it's not adding the header.

I have enabled the module headers with a2enmod headers and confirmed it is enabled with phpinfo(). I have added many variations of the header command to /etc/apache2/sites-available/website.conf before reloading or restarting apache, but none of them are showing:

Header always append Testing1 "ok"
Header always set Testing2 "ok"
Header always add Testing3 "ok"
Header always merge Testing4 "ok"
Header append Testing5 "ok"
Header set Testing6 "ok"
Header add Testing7 "ok"
Header merge Testing8 "ok"

If I purposefully make a mistake like setting Header xappend Testing I get an error when restarting apache2 and the message first argument must be 'add', 'set', 'setifempty', 'append', 'merge', 'unset', 'echo', 'note', 'edit', or 'edit*'., so I'm sure the config is being loaded.

I've tested with a .js, .html and .php file and none are showing the headers. I have made sure I's not caching (I get a 200 OK result) with different browsers and online tools.

I also tried the expires module, but it's not showing either. I almost feel like the headers are removed again in a later stage. But there is no .htaccess file and the javascript and html file have no options to change the headers.

Minimized virtual host file I use for testing:

<VirtualHost *:*>
        ServerName static.example.com

        ServerAdmin [email protected]
        DocumentRoot /mnt/sdc1/webserver/_web

        Header always append Testing1 "ok"
        Header always set Testing2 "ok"
        Header always add Testing3 "ok"
        Header always merge Testing4 "ok"    
</VirtualHost>

I've run out of ideas where to check next. What could prevent the headers to show?

2
  • Wrong VirtualHost? Using not matching servername?
    – AlexD
    Commented Jan 26 at 11:45
  • The virtual host does point to the right directory, else I wouldn't see the files at all. So it seems that at least the DocumentRoot dir is coming from this virtualhost config. Commented Jan 26 at 12:53

0

You must log in to answer this question.

Browse other questions tagged .