![Nginx 正在运行,但不提供 php 文件](https://linux22.com/image/701972/Nginx%20%E6%AD%A3%E5%9C%A8%E8%BF%90%E8%A1%8C%EF%BC%8C%E4%BD%86%E4%B8%8D%E6%8F%90%E4%BE%9B%20php%20%E6%96%87%E4%BB%B6.png)
我正在尝试在 ubuntu 16.0 上设置 Nginx 和 php 7,在此之前我只在 Windows 上使用过 WAMP,我已经成功安装了 nginx 和 php,当我在终端上运行此命令时:
卷曲-I-vhttp://本地主机/
它表明 nginx 服务器正常,但是它不提供 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
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.php INFO.PHP index.html index.htm index.nginx-debian.html;
server_name 127.0.0.1:80;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
任何帮助都将受到赞赏,问候。
答案1
检查 php7.0-fpm 服务是否正在运行。
systemctl list-units 'php*'
当 php-fpm 状态良好时,结果是活动且正在运行。如果发现 php7.0-fpm 没有运行,请启用它。
systemctl list-units 'php*'
然后再次检查。
然后,尝试
curl -v 'http://localhost/index.php'
是否可以获得 php 结果,您将检查位置/块中的 try_files 指令。
答案2
两个原因。
- 您的 php7.0-fpm 可能无法正常工作。请检查其状态。
您正在将所有 php 扩展文件传递给 fastcgi_pass
unix:/run/php/php7.0-fpm.sock;
,即临时创建的套接字。可能是您的 php7.0-fpm 在不同的套接字上运行。虽然它是默认端口,但我仍然会要求您在此处检查侦听端口和用户组的配置。您可以在以下位置找到 php7-fpm 的配置/etc/php/7.0/fpm/pool.d/www.conf
仍有问题 请参阅本文