[英]Niginx Downloads PHP files Instead of Executing index.php
Nginx下载php文件而不是执行
具有PHP 7.0的Ubuntu 16.04 Nginx。
Nginx版本:Nginx / 1.10.3(Ubuntu)
我必须执行的文件位于/var/lib/customdir/customfiles/index.php
这是我的默认配置文件。 出于安全原因,我删除了目录的实际名称。
# 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;
}
我尝试了上述方法的许多不同变体,但均未成功。
任何帮助将不胜感激。
尝试这个:
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
(指向绝对dir /var
而不是相对目录)。
1)根目录应该是root /var/lib/customdir/customfiles
(无文件index.php)。
2)检查/etc/php7.0/fpm/php.ini
cgi.fix_pathinfo
值(或/etc/php/7.0/fpm/php.ini
)? 需要将其设置为0
。
3)将您的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
}
使用以下命令测试配置:
sudo nginx -t
在重新加载nginx配置之前,查看是否有任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.