[英]Niginx Downloads PHP files Instead of Executing index.php
Nginx downloads php file instead executing Nginx下载php文件而不是执行
Ubuntu 16.04 Nginx with PHP 7.0. 具有PHP 7.0的Ubuntu 16.04 Nginx。
nginx version: nginx/1.10.3 (Ubuntu) Nginx版本:Nginx / 1.10.3(Ubuntu)
The files I have to execute are located in /var/lib/customdir/customfiles/index.php
我必须执行的文件位于
/var/lib/customdir/customfiles/index.php
This is my default conf file. 这是我的默认配置文件。 I have removed the actual names of the directories for security reasons.
出于安全原因,我删除了目录的实际名称。
# 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;
}
I have tried many different variations of the above without success. 我尝试了上述方法的许多不同变体,但均未成功。
Any assistance would be greatly appreciated. 任何帮助将不胜感激。
Try this: 尝试这个:
root /var/lib/customdir/customfiles/
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
}
here I've updated root
(to point to root not to file) and updated fastcgi_pass
(to point to absolute dir /var
not to relative one). 在这里,我更新了
root
(指向不是文件的根目录)和fastcgi_pass
(指向绝对dir /var
而不是相对目录)。
1) The root should be root /var/lib/customdir/customfiles
(without file index.php). 1)根目录应该是
root /var/lib/customdir/customfiles
(无文件index.php)。
2) Check cgi.fix_pathinfo
value in /etc/php7.0/fpm/php.ini
(or /etc/php/7.0/fpm/php.ini
)? 2)检查
/etc/php7.0/fpm/php.ini
cgi.fix_pathinfo
值(或/etc/php/7.0/fpm/php.ini
)? It needs to be set to 0
. 需要将其设置为
0
。
3) Modify your location ~ \\.php$
directive as: 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
}
Test the configuration with: 使用以下命令测试配置:
sudo nginx -t
to see if there is any error before you reload the nginx configuration. 在重新加载nginx配置之前,查看是否有任何错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.