PHP180,【CentOS 7LNMP架构31】,nginx解析php的配置#180108

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 <?php

2 phpinfo();

[root@localhost ~]# curl -x 127.0.0.1:80 test.com/3.php

phpinfo();

[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 -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: 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 -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: 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.php

502 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.0

2018/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_64

2018/03/02 16:07:03 [notice] 7416#0: getrlimit(RLIMIT_NOFILE): 1024:4096

2018/03/02 16:07:03 [notice] 7417#0: start worker processes

2018/03/02 16:07:03 [notice] 7417#0: start worker process 7418

2018/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 restart

Restarting 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.sock

listen.mode = 666

user = php-fpm

group = php-fpm

pm = dynamic

pm.max_children = 50

pm.start_servers = 20

pm.min_spare_servers = 5

pm.max_spare_servers = 35

pm.max_requests = 500

rlimit_files = 1024

修改于 180108

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值