我在nginx中使用CentOS7。为此我需要动态robots.txt,我尝试使用从robots.txt到robots.php的重定向。但是如果是site.com/robots.txt,我会看到robots.php文件中的文本,如果是site.com/robots.php,我会看到运行这个程序的结果。我如何修复site.com/robots.txt给我运行robots.php的结果?在nginx中,我使用下一段代码:
location /robots.txt { alias /home/xxx/web/site.ru/public_html/robots.php; }发布于 2021-02-27 02:35:16
虽然注释中的rewrite方法可以工作,但值得注意的是,正确的解决方案是完全匹配位置,它无条件地将请求定向到PHP-FPM,如下所示:
location = /robots.txt {
fastcgi_param SCRIPT_FILENAME $document_root/robots.php;
include fastcgi_params;
# override SCRIPT_NAME which was set in fastcgi_params
fastcgi_param SCRIPT_NAME /robots.php;
fastcgi_pass unix:/var/run/php-fpm/example.com.sock;
}https://stackoverflow.com/questions/66387218
复制相似问题