Nginx和PHP-FPM – 找不到.php文件 – 无法找出原因

前端之家收集整理的这篇文章主要介绍了Nginx和PHP-FPM – 找不到.php文件 – 无法找出原因前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我已经对这些问题进行了几天阅读,诚然,我是一名Nginx新手.我已经阅读过官方和非官方文档,似乎无法解决我的问题.希望这里有人能帮助我.

我可以服务我的html页面,例如403,404和50x.html,所以我知道Nginx正在以某种身份工作.我的https重定向也有效.

我可以在9001上telnet到PHP FPM.

我的所有权限都是正确的,至少对我而言.

我在下面列出了相关配置文件输出

网站可用/默认:

server
{
        listen                  [::]:80;
        server_name             domain.com;
        return                  301 https://domain.com$request_uri;
        #rewrite                ^ https://domain.com$request_uri? permanent;
}
server
{
        listen 443              default ssl;
        server_name             domain.com;
        ssl                     on;
        ssl_certificate         /etc/ss-certificates/ss-domain.com.crt;
        ssl_certificate_key     /etc/ss-certificates/ss-domain.com.key;

        root                    /var/www/domain.com/wwwroot;
        index                   index.PHP;
        access_log              /var/www/domain.com/logs/access.log combined;
        error_log               /var/www/domain.com/logs/error.log debug;

        error_page              404 /404.html;
        error_page              403 /403.html;
        error_page              500 502 503 504 /50x.html;

        location /
        {
                try_files       $uri $uri/ /index.PHP?q=$uri&$args;
        }

        location ~ \.PHP$
        {
                try_files       $uri =404;
                include         fastcgi_params;
                fastcgi_param   HTTPS                   on;
                fastcgi_param   QUERY_STRING            $query_string;
                fastcgi_param   REQUEST_METHOD          $request_method;
                fastcgi_param   CONTENT_TYPE            $content_type;
                fastcgi_param   CONTENT_LENGTH          $content_length;
                fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
                fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
                fastcgi_param   REQUEST_URI             $request_uri;
                fastcgi_param   DOCUMENT_URI            $document_uri;
                fastcgi_param   DOCUMENT_ROOT           $document_root;
                fastcgi_param   SERVER_PROTOCOL         $server_protocol;
                fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
                fastcgi_param   SERVER_SOFTWARE         Nginx;
                fastcgi_param   REMOTE_ADDR             $remote_addr;
                fastcgi_param   REMOTE_PORT             $remote_port;
                fastcgi_param   SERVER_ADDR             $server_addr;
                fastcgi_param   SERVER_PORT             $server_port;
                fastcgi_param   SERVER_NAME             $server_name;
                fastcgi_pass    127.0.0.1:9001;
        }

        location ~ /\.ht
        {
                deny all;
        }

        location = /favicon.ico
        {
                log_not_found off;
                access_log off;
        }

}

pool.d / domain.com.conf:

[domain]
listen  = 127.0.0.1:9001
user    = www-data
group   = www-data
pm = dynamic
pm.max_children = 10
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
chroot = /var/www/domain.com/wwwroot/
chdir = /

网站目录:

ll -s -R /var/www/domain.com/
/var/www/domain.com/:
total 16
4 drwxr-xr-x 4 www-data www-data 4096 Jul 23 22:48 ./
4 drwxr-xr-x 3 root     root     4096 Jul 22 22:49 ../
4 drwxr-xr-x 2 www-data www-data 4096 Jul 25 22:59 logs/
4 drwxr-xr-x 2 www-data www-data 4096 Jul 28 15:00 wwwroot/

/var/www/domain.com/logs:
total 516
  4 drwxr-xr-x 2 www-data www-data   4096 Jul 25 22:59 ./
  4 drwxr-xr-x 4 www-data www-data   4096 Jul 23 22:48 ../
 24 -rw-r--r-- 1 www-data www-data  18128 Jul 28 15:19 access.log
484 -rw-r--r-- 1 www-data www-data 490826 Jul 28 15:20 error.log

/var/www/domain.com/wwwroot:
total 28
4 drwxr-xr-x 2 www-data www-data 4096 Jul 28 15:00 ./
4 drwxr-xr-x 4 www-data www-data 4096 Jul 23 22:48 ../
4 -rw-r--r-- 1 www-data www-data   53 Jul 26 22:56 403.html
4 -rw-r--r-- 1 www-data www-data   53 Jul 26 22:55 404.html
4 -rw-r--r-- 1 www-data www-data  383 Jul 23 22:42 50x.html
4 -rw-r--r-- 1 www-data www-data 1406 Jul 25 21:46 favicon.ico
4 -rwxr-xr-x 1 www-data www-data   88 Jul 22 22:58 index.PHP*

Nginx.conf:

user www-data;
worker_processes 4;
pid /var/run/Nginx.pid;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        # server_tokens off;

        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;

        include /etc/Nginx/mime.types;
        default_type application/octet-stream;

        ##
        # Logging Settings
        ##

        access_log /var/log/Nginx/access.log;
        error_log /var/log/Nginx/error.log;

        ##
        # Gzip Settings
        ##

        gzip on;
        gzip_disable "msie6";

        # gzip_vary on;
        # gzip_proxied any;
        # gzip_comp_level 6;
        # gzip_buffers 16 8k;
        # gzip_http_version 1.1;
        # gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+RSS text/javascript;

        ##
        # Nginx-naxsi config
        ##
        # Uncomment it if you installed Nginx-naxsi
        ##

        #include /etc/Nginx/naxsi_core.rules;

        ##
        # Nginx-passenger config
        ##
        # Uncomment it if you installed Nginx-passenger
        ##

        #passenger_root /usr;
        #passenger_ruby /usr/bin/ruby;

        ##
        # Virtual Host Configs
        ##

        include /etc/Nginx/conf.d/*.conf;
        include /etc/Nginx/sites-enabled/*;
}

在此先感谢大家的帮助.

问候,

JG

最佳答案
您的访问/错误日志中有什么内容吗?

另外,为什么要包含fastcgi_params然后几乎全部定义它们?

这是我的位置块在Nginx中使用PHP-fpm的样子:

    location ~ \.PHP${

            try_files $uri =404;
            fastcgi_intercept_errors on;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.PHP;
            fastcgi_param  SCRIPT_FILENAME  /path/to/site.com/public$fastcgi_script_name$
            fastcgi_param  PATH_INFO $fastcgi_script_name;
            include fastcgi_params;
    }

尝试将fastcgi_pass向上移动到顶部.

原文链接:https://www.f2er.com/nginx/435258.html

猜你在找的Nginx相关文章