Ребят подскажите как заставить работать robots.php под Nginx + PHP-FPM?
Прописал
location = /robots.txt {
allow all;
rewrite ^/robots\.txt$ /robots.php;
}
получаю 403 Forbidden при обращении к нему
Код: Выделить всё
location = /robots.txt {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/robots.php;
fastcgi_pass unix:/run/php/php-fpm.sock; # ваш сокет/порт, как в location для php
}все так жеTom писал(а): ↑02 окт 2026, 15:23 А так ?
Код: Выделить всё
location = /robots.txt { rewrite ^ /robots.php last; }
nikifalex писал(а): ↑02 окт 2026, 16:19 403 тут отдаёт не сам rewrite, а другой location. Скорее всего в конфиге есть правило, которое запрещает прямой вызов .php, кроме index.php (в сборках под OpenCart это частое дело), и robots.php под него попадает.
Проще всего отдать его в PHP-FPM прямо из этого location, без rewrite:
Код: Выделить всё
location = /robots.txt { include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root/robots.php; fastcgi_pass unix:/run/php/php-fpm.sock; # ваш сокет/порт, как в location для php }
Так другие правила уже не мешают. После правки nginx -t и reload.
Код: Выделить всё
location = /robots.txt {
include /etc/nginx/vhosts-resources/eburg.chernil.net/dynamic/*.conf;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/robots.php;
fastcgi_pass unix:/var/www/php-fpm/4.sock;
}Код: Выделить всё
rewrite ^/robots\.txt$ /robots.php last;Код: Выделить всё
location ~ ^/(index|admin/index)\.php {Код: Выделить всё
location ~ ^/(index|admin/index|robots)\.php {Код: Выделить всё
server {
server_name eburg.chernil.net www.eburg.chernil.net;
listen 37.230.113.70:80;
include /etc/nginx/vhosts-includes/*.conf;
return 301 https://$host$request_uri;
}
server {
server_name eburg.chernil.net www.eburg.chernil.net;
ssl_certificate "/var/www/httpd-cert/www-root/eburg.chernil.net_le3.crtca";
ssl_certificate_key "/var/www/httpd-cert/www-root/eburg.chernil.net_le3.key";
ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
add_header Strict-Transport-Security "max-age=31536000;";
ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
charset off;
index index.php index.html;
disable_symlinks if_not_owner from=$root_path;
include /etc/nginx/vhosts-includes/*.conf;
include /etc/nginx/vhosts-resources/eburg.chernil.net/*.conf;
access_log /var/www/httpd-logs/eburg.chernil.net.access.log;
error_log /var/www/httpd-logs/eburg.chernil.net.error.log notice;
ssi on;
set $root_path /var/www/www-root/data/www/prof-66.ru;
root $root_path;
if ($host = www.eburg.chernil.net) {
return 301 https://eburg.chernil.net$request_uri;
}
rewrite ^/robots\.txt$ /robots.php last;
if (!-e $request_filename) {
rewrite ^/(.+)$ /index.php?_route_=$1 last;
}
location / {
location ~ ^/(index|admin/index|robots)\.php {
try_files /does_not_exists @php;
}
location = /sitemap.xml {
rewrite ^/(.*)$ /index.php?route=extension/feed/google_sitemap last;
}
location ~ /\. {
deny all;
}
location ~ ^/system/ {
deny all;
}
location ~* \.(php|log|tpl|txt|twig|xml|ini)$ {
deny all;
}
location ~ [^/]\.ph(p\d*|tml)$ {
try_files /does_not_exists @php;
}
location ~* ^.+\.(jpg|jpeg|gif|png|svg|webp|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff|woff2)$ {
expires 365d;
}
}
location @php {
include /etc/nginx/vhosts-resources/eburg.chernil.net/dynamic/*.conf;
fastcgi_index index.php;
fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@eburg.chernil.net";
fastcgi_pass unix:/var/www/php-fpm/4.sock;
fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
try_files $uri =404;
include fastcgi_params;
}
gzip on;
gzip_comp_level 5;
gzip_disable "msie6";
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
include /etc/nginx/users-resources/www-root/*.conf;
listen 37.230.113.70:443 ssl;
}