I don't want to use php inside a page itself or a twig file , especially because these pages are automatically generated (they are not in my pages dashboards).
Thank you for your response.
I think you may confuse crawling with indexing such urls from any search robots.
While the robots.txt file is here to prevent the robots from crawling desired urls, it does not tells them to un-index them from their databases (which is the result i want).
I want to allow access to those urls (with a 200 HTTP code) because they exist but i don't want them to be indexed. This is why i am trying to send this noindex X-Robots-Tag in the HTTP header.
Configuration of the nginx config file seems tricky because the url exists but is "generated" by grav (or the grav theme i use) even though the file itself doesn't exist explicitly in the page dashboard in the backend. They are "category" urls or "page collections".
I am still stuck with that so if anyone visiting this post has an idea. Please share it with me (and others reading).
For those interested, i got helped by someone from the #nginx channel on Freenode IRC. Here is the solution that does the trick (wasn't easy to find and is not trivial).
<details>
<summary>Solution: Robot tag in HTTP Header</summary>
PHP
map$request_uri$x_robots{default"";~category:noindex;}server{indexindex.htmlindex.php;## Begin - Server Inforoot/home/grav/www/html;server_nameexample.comwww.example.com;## End - Server Info## Begin - Index# for subfolders, simply adjust:# location /subfolder {# and the rewrite to use /subfolder/index.phplocation/{try_files$uri$uri//index.php?$query_string; }
## End - Index## Begin - Security# deny all direct access for these folderslocation~*/(\.git|cache|bin|logs|backup|tests)/.*$ {return403;}# deny running scripts inside core system folderslocation~*/(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ {return403;}# deny running scripts inside user folderlocation~*/user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ {return403;}# deny access to specific files in the root folderlocation~/(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess){return403;}## End - Securityadd_headerX-Robots-Tag$x_robots;## Begin - PHPlocation~ \.php$ {# fastcgi_index index.php;includesnippets/fastcgi-php.conf;# Choose either a socket or TCP/IP addressfastcgi_passunix:/var/run/php/php7.3-fpm.sock;# legacy (e.g. PHP 5) logic# fastcgi_pass unix:/var/run/php5-fpm.sock;# fastcgi_pass 127.0.0.1:9000;# fastcgi_split_path_info ^(.+\.php)(/.+)$;}## End - PHPlisten[::]:443sslipv6only=on;# managed by Certbotlisten443ssl;# managed by Certbotssl_certificate/etc/letsencrypt/live/example.com/fullchain.pem;# managed by Certbotssl_certificate_key/etc/letsencrypt/live/example.com/privkey.pem;# managed by Certbotinclude/etc/letsencrypt/options-ssl-nginx.conf;# managed by Certbotssl_dhparam/etc/letsencrypt/ssl-dhparams.pem;# managed by Certbot}server{if($host=www.example.com){return301https://example.com$request_uri;}# managed by Certbotif($host=example.com){return301https://$host$request_uri;}# managed by Certbotlisten80;listen[::]:80;server_nameexample.comwww.example.com;return404;# managed by Certbot}