情况如下。我在运行 Ajenti 的 ubuntu 14.04 VM 上安装了 prestashop 1.7.1,因此对我来说是 php-fpm 和 nginx。在查看了大量教程和一些自定义配置后,我设法让一切正常工作。但是我刚刚安装了一个新模块,当调用执行工作的 php 文件(生成 xml)时,我得到的是文件而不是处理后的结果。我检查了文件权限,甚至在所有文件上尝试了 777。我注意到问题出在哪里,nginx 配置是:
set $admin_dir /admin_folder;
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
# Supposed to be the case but we never know
# text/html;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
# Old image system ?
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
rewrite ^/c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ /img/c/$1$2$3.jpg last;
rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ /img/c/$1$2.jpg last;
#Symfony controllers
location ~ /(international|_profiler|modules|product|combination|specific-price|attachment)/(.*)$ {
try_files $uri $uri/ /index.php?q=$uri&$args $admin_dir/index.php$is_args$args;
}
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
error_page 404 /index.php?controller=404;
add_header Strict-Transport-Security max-age=31536000;
location ~ /\. {
deny all;
}
location ~ \.tpl {
deny all;
}
location ~ ^/admin_folder/index.php/(.*) {
if (!-e $request_filename) {
rewrite ^/.*$ /admin_folder/index.php last;
}
}
location ~ /en/index.php {
rewrite ^/en/index\.php$ /index.php redirect;
}
location ~ /el/index.php {
rewrite ^/el/index\.php$ /index.php redirect;
}
location ^~ /modules/xmlfeeds/api/xml.php {
#Here is the problem
return 501;
}
有什么建议么?
答案1
您需要将 PHP 处理location
块包含在.xml
块内,以便它能够执行 PHP 脚本。否则它只会执行默认操作,即直接将文件发送到客户端。
答案2
看起来您没有包含任何实际处理 .php 文件的方法。
您需要在该位置添加类似的内容:
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
请注意,我说的是“类似”,因为这将根据您的配置因服务器而异。Nginx 需要知道将 php 请求传递到哪里,并从 fastcgi 获取内容,因此您需要告诉它如何执行此操作。上面的代码片段可能会做到这一点 :)