hellopasswd
nginx解析php的配置
- 配置 location ~ .php$ { include fastcgi_params; fastcgi_pass unix:/tmp/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/test.com$fastcgi_script_name; }
- fastcgi_pass #用于指定php-fpm监听的地址或socket
[root@localhost ~]# vi /data/wwwroot/test.com/3.php 1
[root@localhost ~]# vi /usr/local/nginx/conf/vhost/test.com.conf 37 location ~ .*(upload|image)/.*\.php$ 38 { 39 deny all; 40 } 41 42 if ($http_user_agent ~* 'Spider/3.0|YoudaoBot|Tomato') 43 { 44 return 403; 45 } 46 47 location ~ \.php$ 48 { 49 include fastcgi_params; 50 fastcgi_pass unix:/tmp/php-fcgi.sock; 51 fastcgi_index index.php; 52 fastcgi_param SCRIPT_FILEMANE /data/wwwrooot/test.com$fastcgi_script_name; 53 } 54 55 access_log /tmp/test.com.log; 56 }[root@localhost ~]# /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload
502 Bad的问题
[root@localhost ~]# vi /usr/local/nginx/conf/vhost/test.com.conf将 50 fastcgi_pass unix:/tmp/php-fcgi.sock;改错为 50 fastcgi_pass unix:/tmp/php-cgi.sock;
[root@localhost ~]# /usr/local/nginx/sbin/nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload[root@localhost ~]# curl -x 127.0.0.1:80 test.com/test.php502 Bad Gateway 502 Bad Gateway
nginx/1.8.0 [root@localhost ~]# tail /usr/local/nginx/logs/nginx_error.log 2018/03/02 16:07:03 [notice] 7416#0: nginx/1.8.02018/03/02 16:07:03 [notice] 7416#0: built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 2018/03/02 16:07:03 [notice] 7416#0: OS: Linux 3.10.0-123.el7.x86_642018/03/02 16:07:03 [notice] 7416#0: getrlimit(RLIMIT_NOFILE): 1024:40962018/03/02 16:07:03 [notice] 7417#0: start worker processes2018/03/02 16:07:03 [notice] 7417#0: start worker process 74182018/03/02 16:07:03 [notice] 7417#0: start worker process 7419
解释
location ~ \.php$ { include fastcgi_params;# include语句会获取指定文件中存在的所有文本/代码/标记,并复制到使用 include 语句的文件中。 fastcgi_pass unix:/tmp/php-fcgi.sock;# fastcgi_pass 127.0.0.1:9000;# 指定FastCGI服务器监听端口与地址,可以是本机或者其它: fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /data/wwwroot/zlw.com$fastcgi_script_name;# #脚本文件请求的路径 }
[root@localhost ~]# vi /data/wwwroot/test.com/3.php
502找不到sock
将/usr/local/nginx/conf/vhost/test.com.conf中的fastcgi_pass unix:/tmp/php-fcgi.sock;改为php-cgi.sock
更改级别
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf 1 user nobody nobody; 2 worker_processes 2; 3 error_log /usr/local/nginx/logs/nginx_error.log crit; 4 pid /usr/local/nginx/logs/nginx.pid; 5 worker_rlimit_nofile 51200; 6 events 7 { 8 use epoll; 9 worker_connections 6000; 10 } . . .
将crit改为debug为
1 user nobody nobody; 2 worker_processes 2; 3 error_log /usr/local/nginx/logs/nginx_error.log debug; 4 pid /usr/local/nginx/logs/nginx.pid; 5 worker_rlimit_nofile 51200; 6 events 7 { 8 use epoll; 9 worker_connections 6000; 10 } . . .
[root@localhost ~]# /etc/init.d/nginx restartRestarting nginx (via systemctl): [ OK ]
[root@localhost ~]# tail /usr/local/nginx/logs/nginx_error.log
访问时提示没有php-cgi.sock的文件
查询定义的sock文件
error_log = /usr/local/php-fpm/var/log/php-fpm.log[www]listen = /tmp/php-fcgi.socklisten.mode = 666user = php-fpmgroup = php-fpmpm = dynamicpm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500rlimit_files = 1024
修改于 180108