欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

(SOS)ubuntu20, nginx无法解析php文件

程序员文章站 2022-06-16 17:29:31
...

前言:尝试能搜索到("lnmp nginx 访问html正常 访问php 404")的解决案例,都没有得到解决,仍然原因未知,故发帖求助。

 

一.问题现象:html能正常访问,但是访问php的时候就报了404。

(SOS)ubuntu20, nginx无法解析php文件

(SOS)ubuntu20, nginx无法解析php文件

 

二.尝试解决:

百度搜索“lnmp nginx 访问html正常 访问php 404”前9条记录的情况。

一个讲的是nginx.conf中,fastcgi_param,路径这项。

#fastcgi_param  SCRIPT_FILENAME  /home/wangyetao/PhpstormProjects/untitled001$fastcgi_script_name;

fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

第二个讲的是nginx.conf中,fastcgi_pass这项,尝试切换socket方式和端口方式。

nginx.conf中
#fastcgi_pass   127.0.0.1:9000;
fastcgi_pass   unix:/tmp/php-cgi.sock;


php-fpm.conf的配置
[www]
listen = /tmp/php-cgi.sock

我尝试了在百度搜到的这些情况,尝试各种排除和配置修改,无效。

感觉还是php-fpm模块没有被nginx调用到导致的,但始终没有找到思路,求大牛解答???

 

 

三.环境配置:

1).ubuntu&nginx&php-fpm&php环境

aaa@qq.com:~$ uname -a
Linux wangyetao-Lenovo-G510 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
aaa@qq.com:~$ date
2020年 09月 06日 星期日 14:20:32 CST
aaa@qq.com:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal

aaa@qq.com:~$ nginx -v
nginx version: nginx/1.15.10
aaa@qq.com:~$ php-fpm -v
PHP 5.5.38 (fpm-fcgi) (built: Apr 24 2019 23:46:49)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies
aaa@qq.com:~$ php -v
PHP 5.5.38 (cli) (built: Apr 24 2019 23:46:43) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend Guard Loader v3.3, Copyright (c) 1998-2014, by Zend Technologies

2)lnmp:lnmp1.5

 

3)nginx.conf(/usr/local/nginx/conf/nginx.conf)

user  www www;

worker_processes auto;

error_log  /home/wwwlogs/nginx_error.log  crit;

pid        /usr/local/nginx/logs/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        default_type  application/octet-stream;

        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;

server
    {
        listen 80 default_server;
        #listen [::]:80 default_server ipv6only=on;
        server_name _;
        index index.html index.htm index.php;
        root  /home/wwwroot/default;

        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php.conf;
	
        location /nginx_status
        {
            stub_status on;
            access_log   on;
        }
        

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/access.log;
    }
    include vhost/*.conf;
}

vhost/untitled001.conf(/usr/local/nginx/conf/vhost/untitled001.conf)

user  www www; 
worker_processes 1;

server {
        listen  80;
        server_name  www.untitled001.loc;
 
        access_log  /home/wwwlogs/access_untitled001.log main;
 
	include enable-php.conf;
 
        location / {
            root   /home/wangyetao/PhpstormProjects/untitled001;
            index  index.php index.html index.htm;
        }
 
        
 
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$
        {
            #fastcgi_pass   127.0.0.1:9000;
            fastcgi_pass   unix:/tmp/php-cgi.sock;
            #fastcgi_pass   unix:/tmp/php-cgi-55.sock;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /home/wangyetao/PhpstormProjects/untitled001$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
 
        
	
        location /nginx_status
        {
            stub_status on;
            access_log   on;
        }
        

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }
        

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }
}

php-fpm.conf(/usr/local/php/etc/php-fpm.conf)

[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
log_level = notice

[www]
listen = /tmp/php-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log

enable-php.conf(/usr/local/nginx/conf/enable-php.conf)

        location ~ [^/]\.php(/|$)
        {
            try_files $uri /index.php =404;
            fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

 

 

标记:"GEEK+"原创博主大赛