How to add Apache Headers in Linux 12?

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Delaney martin
    Senior Member
    • Jun 2022
    • 186

    How to add Apache Headers in Linux 12?

    VPS Hosting
    Hi,

    I have a problem with Apache2 headers. My needs are to add the HTTP header “X-Served-By” with the server hostname as the value.

    Any suggestions?
  • Rachel S
    Senior Member
    • Apr 2022
    • 182

    #2
    Hey, this can help.

    Check that you have enabled the headers module with sudo a2enmod headers

    You can add the header in your site's virtual host config or in the global Apache config (apache2.conf or 000-default.conf):

    sudo nano /etc/apache2/sites-available/000-default.conf

    Ensure the block <VirtualHost *:80> will look like:

    ...

    SetEnv HOSTNAME ${HOSTNAME}

    Header set X-Served-By "%{HOSTNAME}e"

    </VirtualHost>


    At last, don't forget to restart Apache: sudo systemctl restart apache2

    Comment

    • wisly.k
      Senior Member
      • May 2022
      • 189

      #3
      Hi, First, you need to check if the header is present using:

      curl -I http://your_server_ip_or_domain

      Then you can also set the hostname permanently with this line:

      hostnamectl set-hostname your-desired-hostname​

      Comment

      Working...
      X