risbo
October 25, 2023, 1:00am
1
Hello friends, need help
I created a duplicated wordpress template and tried to add some x-robots-tag for specific page in nginx server + PHP FPM
location ~* /f/ {
add_header X-Robots-Tag “noindex, nofollow”;
try_files $uri $uri/ /index.php$is_args$args;
}
/f/ should be no index no follow, That are filters from wp. Tried many combinations but no one works.
Hello @risbo ,
Keep in mind that you should edit both wordpress templates, tpl and stpl.
Did you copy/paste that conf from some web page? I’m asking because you are using the wrong quotes, you are using “ ”
instead of " "
so the add_header
won’t work.
Use this:
location ~* /f/ {
add_header X-Robots-Tag "noindex, nofollow";
try_files $uri $uri/ /index.php$is_args$args;
}
risbo
October 25, 2023, 9:45am
3
sahsanu
October 25, 2023, 10:00am
4
You should not add two locations with the same pattern (remove one of them):
location ~ /f/ {
add_header X-Robots-Tag "noindex, nofollow";
try_files $uri $uri/ /index.php$is_args$args;
}
and
location ~ /f/ {
add_header X-Robots-Tag "noindex, nofollow";
}
Did you rebuild your site after chamging the templates?
risbo
October 25, 2023, 10:17am
5
I keep first code,(nothing changes) what you mean by rebuild? I change that domain first to default wordpress template and than to custom template, then template should apply right?
location ~* /f/ {
add_header X-Robots-Tag "noindex, nofollow";
try_files $uri $uri/ /index.php$is_args$args;
}
sahsanu
October 25, 2023, 10:38am
6
I keep first code,(nothing changes) what you mean by rebuild? I change that domain first to default wordpress template and than to custom template, then template should apply right?
That should be enought to rebuild your site. Rebuild recreates templates for your domain and put the right conf in the right places.
Check whether your changes have been applied:
/home/YOUR_USER/conf/web/YOUR_DOMAIN/nginx.conf
/home/YOUR_USER/conf/web/YOUR_DOMAIN/nginx.ssl.conf
Also, check headers with another browser or using private/incognito mode. If you tell me what is your domain I could check if I see the header.
Also, in pastebin you are using location ~ /f/ {
but now you are using location ~* /f/ {
risbo
October 25, 2023, 10:54am
7
sahsanu
October 25, 2023, 11:37am
8
I’ve tested it with:
location ~ /f/ {
add_header X-Robots-Tag "noindex, nofollow";
try_files $uri $uri/ /index.php$is_args$args;
}
And it is working fine:
$ curl -sI https://dnsip.xyz/c/pre-workout/f/proizvodjaci-activlab/ | grep -i robots
x-robots-tag: noindex, nofollow
Did you reload nginx?
systemctl reload nginx
risbo
October 25, 2023, 11:59am
9
Yes i reload nginx and I can’t see noindex no follow on addon. It says X-robots-tag is not present.
sahsanu
October 25, 2023, 3:53pm
10
I installed a Wordpress to test and this works:
Edit your template and in this block:
location ~ [^/]\.php(/|$) {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass %backend_lsnr%;
include %home%/%user%/conf/web/%domain%/nginx.fastcgi_cache.conf*;
if ($request_uri ~* "/wp-admin/|/wp-json/|wp-.*.php|xmlrpc.php|index.php|/store.*|/cart.*|/my-account.*|/checkout.*") {
set $no_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
set $no_cache 1;
}
}
add this:
if ($request_uri ~* "/.*/f/.*") {
add_header X-Robots-Tag "noindex, nofollow";
}
So the final block will look like:
location ~ [^/]\.php(/|$) {
try_files $uri =404;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param HTTP_EARLY_DATA $rfc_early_data if_not_empty;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.1-fpm-dnsip.xyz.sock;
include /home/master/conf/web/dnsip.xyz/nginx.fastcgi_cache.conf*;
if ($request_uri ~* "/.*/f/.*") {
add_header X-Robots-Tag "noindex, nofollow";
}
if ($request_uri ~* "/wp-admin/|/wp-json/|wp-.*.php|xmlrpc.php|index.php|/store.*|/cart.*|/my-account.*|/checkout.*") {
set $no_cache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
set $no_cache 1;
}
}
risbo
October 25, 2023, 4:51pm
11
Thank you, this is solution. I appreciate
1 Like
system
Closed
November 24, 2023, 4:51pm
12
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.