Nginx下载php文件而不是执行
Ubuntu 16.04 Nginx和PHP 7.0。
nginx版本:nginx / 1.10.3(Ubuntu)
我必须执行的文件位于/var/lib/customdir/customfiles/index.php
这是我的默认conf文件。出于安全原因,我已删除了目录的实际名称。
# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
root /var/lib/customdir/customfiles/index.php
# root /var/www/html;
# root /usr/share/nginx/html;
# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;
server_name 54.252.213.xxx;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:var/run/php/php7.0-fpm.sock;
}
location ~ /\.ht {
deny all;
}
我尝试了上述方法的许多不同变体,但没有成功。
任何帮助将不胜感激。
答案 0 :(得分:0)
尝试一下:
root /var/lib/customdir/customfiles/
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
在这里,我更新了root
(指向根而不是文件)和更新fastcgi_pass
(指向绝对目录/var
而不是相对目录)。
答案 1 :(得分:0)
1)根目录应为+----------+----------+
(无文件index.php)。
2)检查root /var/lib/customdir/customfiles
(或cgi.fix_pathinfo
)中的/etc/php7.0/fpm/php.ini
值吗?需要将其设置为/etc/php/7.0/fpm/php.ini
。
3)将0
指令修改为:
location ~ \.php$
使用以下命令测试配置:
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; #you have a missing / before var
fastcgi_split_path_info ^(.+\.php)(/.+)$; #add this line
}
在重新加载nginx配置之前查看是否有任何错误。