Cannot add response headers

Keywords: WordPress + NGINX + SSL - AWS - Technical issue - Other
bnsupport ID: e3fe370e-2719-a08b-a259-ef332136a593
Description:
I’m trying to add X-Robots-Tag headers but the response headers are not returned.

I added the following in /opt/bitnami/aps/wordpress/conf/nginx-app.conf:

location / {
    add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
}

also tried to do this under /opt/bitnami/nginx/conf/bitnami/bitnami.conf, but still, headers are not returned when I restart services and visit or curl the site.

Hi @george3,

What’s the output of the curl command?

Regards,
Michiel

@michiel
curl L -I https://example.com returns the following:

curl: (6) Could not resolve host: L
HTTP/2 200
server: nginx/1.18.0
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
x-powered-by: PHP/7.4.14
link: <https://example.com/wp-json/>; rel="https://api.w.org/"
link: <https://example.com/wp-json/wp/v2/pages/56>; rel="alternate"; type="application/json"
link: <https://example.com/>; rel=shortlink
x-frame-options: SAMEORIGIN
date: Fri, 23 Apr 2021 03:08:38 GMT
x-page-speed: 1.13.35.2-0
cache-control: max-age=0, no-cache

Hi @george3,

Can you run this instead?

curl -LI https://example.com

Replacing example.com with your own domain?

Regards,
Michiel

Sorry had a typo there, but with curl -LI result is the same:
HTTP/2 200

server: nginx/1.18.0
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
x-powered-by: PHP/7.4.14
link: <https://example.com/wp-json/>; rel="https://api.w.org/"
link: <https://example.com/wp-json/wp/v2/pages/56>; rel="alternate"; type="application/json"
link: <https://example.com/>; rel=shortlink
x-frame-options: SAMEORIGIN
date: Tue, 27 Apr 2021 22:47:33 GMT
x-page-speed: 1.13.35.2-0
cache-control: max-age=0, no-cache

Any thoughts on this? Where’s the best place to add headers??

Hi @george3,

Can you try this instead?

location ~* {
add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
} 

Regards,
Michiel


Please click on :heart: if you think my answer was helpful.


@michel so that does send the headers now, but the problem is that the wordpress site no longer works. Instead when I visit it, it downloads a file with these contents:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define( 'WP_USE_THEMES', true );

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';

Hi @george3,

Can you add it to the location ~ \.php$ section of the /opt/bitnami/apps/wordpress/conf/nginx-app.conf file instead?

location ~ \.php$ {
    add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_read_timeout 300;
    fastcgi_pass unix:/opt/bitnami/php/var/run/www.sock;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include fastcgi_params;
}

Regards,
Michiel

@michiel Perfect, that worked. Thank you!