Nginx没有';不提供PHP文件
我安装了一个全新的CentOS7,并作为虚拟机运行。我一直在玩Nginx,因为我一辈子都在使用Apache,现在只是为了好玩和学习,我决定切换到Nginx。我遵循以下两条指南:Nginx没有';不提供PHP文件,php,linux,nginx,Php,Linux,Nginx,我安装了一个全新的CentOS7,并作为虚拟机运行。我一直在玩Nginx,因为我一辈子都在使用Apache,现在只是为了好玩和学习,我决定切换到Nginx。我遵循以下两条指南: 数字海洋 通过一个名为ifnottruenthenfalse的博客 作为我之前研究的一部分,在我失去想法之前,我确实读了一些毫无帮助的东西 在继续之前,我应该说,我为每一个都取了我需要的东西,因为我想使用PHP7.0.x,而不是CentOS 7回购协议(我想是5.4)附带的默认值 这就是我的配置文件的样子: /etc
- 数字海洋
- 通过一个名为ifnottruenthenfalse的博客
/etc/nginx/conf.d/default.conf
server {
listen 80;
server_name centos7.localdomain;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files $uri =404
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
/etc/php-fpm.d/www.conf
[www]
; RPM: apache Choosed to be able to access some dir as httpd
user = nginx
; RPM: Keep a group allowed to write in log dir.
group = nginx
...
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server.
; Default Values: user and group are set as the running user
; mode is set to 0660
listen.owner = nobody
listen.group = nobody
对于www.conf
,除了您在此处看到的值之外,其他值都是默认值。完整的文件是
我创建了文件/var/www/html/index.php
,除了:
<?php
phpinfo();
这是我正在运行的PHP版本:
$ php -v
PHP 7.0.11 (cli) (built: Sep 14 2016 08:28:52) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.11, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans
我错过了什么?如果是,是什么?或者我正在玩的这个设置有什么问题?从最后一段中删除“try_files$uri=404”。这可能会解决你的问题
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
您可以发布以下命令的输出:php-v@Hackerman添加到OP:)文件系统中是否有
/var/run/php fpm/php fpm.sock
?@zerkms是,ls-la/var/run/php fpm/total 4 drwxr-xr-x。2根根80十月9日20:53。drwxr-xr-x。24根根720十月9日20:57-rw-r--r--。1根根目录5十月9日20:53 php-fpm.pid srw rw--。1 nobody nobody 0 Oct 9 20:53 php fpm.sock
(遗憾的是,SO中的注释也应该允许标记格式的文本,但它不允许),因此,现在您有了一个工作配置。花些时间阅读nginx文档,并对其进行修改以满足您的需求。将索引
指令放回原处。
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}