Score:0

Headers set using mod_headers modules in apache are being completely ignored

th flag

So I'm trying to see if I can set reponse headers by configuring them in Apache.

I'm using Debian testing, in case that matters.

My web server is working and I've been using it for multiple websites that I'm developing. So now all I want to do is set a header to see if it works.

This is what I changed in my apache.conf

<Directory /home/web>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        Header set myHeader "Hello Header World"
</Directory>

This is what I host configuration file in /etc/apache2/sites-available/000-default.conf looks like:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /home/web

        AliasMatch ^/vmapi/(.*)$ /home/web/vmapi/api_receiver.php
        AliasMatch ^/inherentvalue/api/(.*)$ /home/web/inherentvalue/api/api.php

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        Header set location "juancito"
        Header set Location "pedrito"
        Header set MyHeader "Hello Joe. It took %D microseconds for Apache to serve this request."

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The alias is there for another project, I'm working on.

Also the output of apache2ctl -M looks like this:

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 headers_module (shared)  <-- It's enabled.
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)

So then I try the following command:

curl -i -s -k -v -X GET "http://localhost/vmportal/css"

And the result is this:

HTTP/1.1 301 Moved Permanently
Date: Wed, 24 Nov 2021 06:32:01 GMT
Server: Apache/2.4.48 (Debian)
Location: http://localhost/vmportal/css/
Content-Length: 313
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="http://localhost/vmportal/css/">here</a>.</p>
<hr>
<address>Apache/2.4.48 (Debian) Server at localhost Port 80</address>
</body></html>

Shouldn't I be seeing ANY of the headers that I set in the response?

Can anyone tell me what I might be doing wrong? Or what the problem could be? Or even how to debug it? (There is nothing in the error logs or the access logs, in case you are wondering).

digijay avatar
mx flag
You get a http 301 response, try the `curl` command again like this: `curl -I http://localhost/vmportal/css/`. Also, rename your header to `X-myHeader`.
th flag
Tried it. Literally nothing changed except I don't get the HTML output on my konsole
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.