博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CentOS 7LNMP架构31】,nginx解析php的配置#180108
阅读量:7186 次
发布时间:2019-06-29

本文共 4092 字,大约阅读时间需要 13 分钟。

hot3.png

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

转载于:https://my.oschina.net/hellopasswd/blog/1604159

你可能感兴趣的文章
九度 1470 调整方阵
查看>>
浏览器是如何工作的?(工作原理)
查看>>
qt中 中文乱码问题
查看>>
海量数据的理想存储方案
查看>>
paip.重装系统后firefox火狐收藏夹的恢复
查看>>
Bootflat – 基于 Bootstrap CSS 框架的扁平化界面
查看>>
用脚本安装IIS
查看>>
编写高质量代码改善C#程序的157个建议[勿选List<T>做基类、迭代器是只读的、慎用集合可写属性]...
查看>>
在netbeans下使用调试PHP的插件XdeBug
查看>>
Struts2 - Check Login Interceptor
查看>>
求最大和连续子向量问题的算法分析
查看>>
Java对象的生命周期与作用域的讨论(转)
查看>>
Android -- 打开本地图片且显示路径
查看>>
文本框下面有两个铵钮,点就加点减就减
查看>>
[工具]Serv-U配置教程
查看>>
Oracle EBS 初始化用户密码
查看>>
ExtJs自学教程(1):一切从API開始
查看>>
创建并调用 DLL(1)
查看>>
location.hash && location.href
查看>>
主从复制延时判断
查看>>