给不同的站点分别配置不同的pool

    1. ## 给两个站点分别配置不同的pool
    2. [root@lnmp ~]# ps -ef |grep php
    3. root 1195 1 0 02:15 ? 00:00:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
    4. php-fpm 1209 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    5. php-fpm 1211 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    6. php-fpm 1212 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    7. php-fpm 1213 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    8. php-fpm 1214 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    9. php-fpm 1215 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    10. php-fpm 1216 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    11. php-fpm 1219 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    12. php-fpm 1220 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    13. php-fpm 1221 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    14. php-fpm 1222 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    15. php-fpm 1228 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    16. php-fpm 1229 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    17. php-fpm 1230 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    18. php-fpm 1231 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    19. php-fpm 1232 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    20. php-fpm 1233 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    21. php-fpm 1234 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    22. php-fpm 1235 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    23. php-fpm 1238 1195 0 02:15 ? 00:00:00 php-fpm: pool www
    24. root 2537 2517 0 02:15 pts/0 00:00:00 grep --color=auto php
    25. # 进入配置文件目录
    26. [root@lnmp ~]# cd /usr/local/php-fpm/etc/
    27. # 添加一个pool为123.com
    28. [root@lnmp etc]# vim php-fpm.conf
    29. [global]
    30. pid = /usr/local/php-fpm/var/run/php-fpm.pid
    31. error_log = /usr/local/php-fpm/var/log/php-fpm.log
    32. [www]
    33. listen = /tmp/php-fcgi.sock
    34. listen.mode = 666
    35. user = php-fpm
    36. group = php-fpm
    37. pm = dynamic
    38. pm.max_children = 50
    39. pm.start_servers = 20
    40. pm.min_spare_servers = 5
    41. pm.max_spare_servers = 35
    42. pm.max_requests = 500
    43. rlimit_files = 1024
    44. [123.com]
    45. listen = /tmp/123.sock
    46. listen.mode = 666
    47. user = php-fpm
    48. group = php-fpm
    49. pm = dynamic
    50. pm.max_children = 50
    51. pm.start_servers = 20
    52. pm.min_spare_servers = 5
    53. pm.max_spare_servers = 35
    54. pm.max_requests = 500
    55. rlimit_files = 1024
    56. # 检查语法
    57. [root@lnmp etc]# /usr/local/php-fpm/sbin/php-fpm -t
    58. [19-Aug-2021 07:13:29] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful
    59. # 重启
    60. [root@lnmp etc]# /etc/init.d/php-fpm restart
    61. Gracefully shutting down php-fpm . done
    62. Starting php-fpm done
    63. # 看到多了新的pool
    64. [root@lnmp etc]# ps -aux |grep php
    65. root 2997 0.4 0.2 231720 4880 ? Ss 07:14 0:00php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
    66. php-fpm 2998 0.0 0.2 231660 4608 ? S 07:14 0:00php-fpm: pool www
    67. php-fpm 2999 0.0 0.2 231660 4608 ? S 07:14 0:00php-fpm: pool www
    68. php-fpm 3000 0.0 0.2 231660 4608 ? S 07:14 0:00php-fpm: pool www
    69. php-fpm 3001 0.0 0.2 231660 4608 ? S 07:14 0:00php-fpm: pool www
    70. php-fpm 3002 0.0 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool www
    71. php-fpm 3003 0.0 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool www
    72. php-fpm 3004 0.0 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool www
    73. php-fpm 3005 0.0 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool www
    74. php-fpm 3006 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    75. php-fpm 3007 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    76. php-fpm 3008 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    77. php-fpm 3009 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    78. php-fpm 3010 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    79. php-fpm 3011 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    80. php-fpm 3012 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    81. php-fpm 3013 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    82. php-fpm 3014 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    83. php-fpm 3015 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    84. php-fpm 3016 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    85. php-fpm 3017 0.0 0.2 231660 4616 ? S 07:14 0:00php-fpm: pool www
    86. php-fpm 3018 0.2 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool 123.com
    87. php-fpm 3019 0.0 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool 123.com
    88. php-fpm 3020 0.0 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool 123.com
    89. php-fpm 3021 0.0 0.2 231660 4612 ? S 07:14 0:00php-fpm: pool 123.com
    90. php-fpm 3022 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    91. php-fpm 3023 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    92. php-fpm 3024 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    93. php-fpm 3025 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    94. php-fpm 3026 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    95. php-fpm 3027 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    96. php-fpm 3028 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    97. php-fpm 3029 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    98. php-fpm 3030 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    99. php-fpm 3031 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    100. php-fpm 3032 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    101. php-fpm 3033 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    102. php-fpm 3034 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    103. php-fpm 3035 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    104. php-fpm 3036 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    105. php-fpm 3037 0.0 0.2 231660 4620 ? S 07:14 0:00php-fpm: pool 123.com
    106. root 3039 0.0 0.0 112820 968 pts/1 S+ 07:14 0:00 grep --color=auto php
    107. [root@lnmp etc]# cd /usr/local/nginx/conf/vhost/
    108. [root@lnmp vhost]# vim default.conf
    109. server
    110. {
    111. listen 80 default_server;
    112. server_name aaa.com;
    113. index index.html index.htm index.php;
    114. root /data/nginx/default;
    115. location ~ \.php$ {
    116. include fastcgi_params;
    117. fastcgi_pass unix:/tmp/123.sock;
    118. fastcgi_index index.php;
    119. fastcgi_param SCRIPT_FILENAME /data/nginx/test.com$fastcgi_script_name;
    120. }
    121. }
    122. # fastcgi_pass unix:/tmp/123.sock; 主要就是修改这一行配置文件选择不同的pool。
    123. [root@lnmp vhost]# /usr/local/nginx/sbin/nginx -t
    124. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    125. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
    126. [root@lnmp vhost]# /usr/local/nginx/sbin/nginx -s reload

    配置 拆分多个pool
    在Nginx.conf

    1. // 进入配置文件目录
    2. [root@lnmp vhost]# cd /usr/local/php-fpm/etc/
    3. // 加入一行include
    4. [root@lnmp etc]# vim php-fpm.conf
    5. [global]
    6. pid = /usr/local/php-fpm/var/run/php-fpm.pid
    7. error_log = /usr/local/php-fpm/var/log/php-fpm.log
    8. include = etc/php-fpm.d/*.conf
    9. // 创建存放配置文件的目录
    10. [root@lnmp etc]# mkdir php-fpm.d
    11. [root@lnmp etc]# cd php-fpm.d/
    12. [root@lnmp php-fpm.d]# vim 123.conf
    13. [123.com]
    14. listen = /tmp/123.sock
    15. listen.mode = 666
    16. user = php-fpm
    17. group = php-fpm
    18. pm = dynamic
    19. pm.max_children = 50
    20. pm.start_servers = 20
    21. pm.min_spare_servers = 5
    22. pm.max_spare_servers = 35
    23. pm.max_requests = 500
    24. rlimit_files = 1024
    25. [root@lnmp php-fpm.d]# vim www.conf
    26. [www]
    27. listen = /tmp/php-fcgi.sock
    28. listen.mode = 666
    29. user = php-fpm
    30. group = php-fpm
    31. pm = dynamic
    32. pm.max_children = 50
    33. pm.start_servers = 20
    34. pm.min_spare_servers = 5
    35. pm.max_spare_servers = 35
    36. pm.max_requests = 500
    37. rlimit_files = 1024
    38. [root@lnmp php-fpm.d]# /usr/local/php-fpm/sbin/php-fpm -t
    39. [19-Aug-2021 07:40:02] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf
    40. test is successful
    41. // 重启服务
    42. [root@lnmp php-fpm.d]# /etc/init.d/php-fpm restart
    43. Gracefully shutting down php-fpm . done
    44. Starting php-fpm done
    45. // 查看一下sock文件
    46. [root@lnmp php-fpm.d]# ls /tmp/*.sock
    47. /tmp/123.sock /tmp/mysql.sock /tmp/php-fcgi.sock
    48. [root@lnmp php-fpm.d]# ps -ef |grep php
    49. root 3075 1 0 07:40 ? 00:00:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
    50. php-fpm 3076 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    51. php-fpm 3077 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    52. php-fpm 3078 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    53. php-fpm 3079 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    54. php-fpm 3080 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    55. php-fpm 3081 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    56. php-fpm 3082 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    57. php-fpm 3083 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    58. php-fpm 3084 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    59. php-fpm 3085 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    60. php-fpm 3086 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    61. php-fpm 3087 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    62. php-fpm 3088 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    63. php-fpm 3089 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    64. php-fpm 3090 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    65. php-fpm 3091 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    66. php-fpm 3092 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    67. php-fpm 3093 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    68. php-fpm 3094 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    69. php-fpm 3095 3075 0 07:40 ? 00:00:00 php-fpm: pool 123.com
    70. php-fpm 3096 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    71. php-fpm 3097 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    72. php-fpm 3098 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    73. php-fpm 3099 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    74. php-fpm 3100 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    75. php-fpm 3101 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    76. php-fpm 3102 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    77. php-fpm 3103 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    78. php-fpm 3104 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    79. php-fpm 3105 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    80. php-fpm 3106 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    81. php-fpm 3107 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    82. php-fpm 3108 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    83. php-fpm 3109 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    84. php-fpm 3110 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    85. php-fpm 3111 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    86. php-fpm 3112 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    87. php-fpm 3113 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    88. php-fpm 3114 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    89. php-fpm 3115 3075 0 07:40 ? 00:00:00 php-fpm: pool www
    90. root 3118 2900 0 07:40 pts/1 00:00:00 grep --color=auto php

    php-fpm 定义open_baseddir

    1. # 修改配置文件,特意配置为错误路径
    2. # 添加一行配置文件,其中test.com的路径为错误路径
    3. [root@lnmp php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
    4. php_admin_value[open_basedir]=/data/nginx/wwwtest.com:/tmp/
    5. [root@lnmp php-fpm.d]# /etc/init.d/php-fpm restart
    6. Gracefully shutting down php-fpm . done
    7. Starting php-fpm done
    8. # 测试发现这些PHP文件都无法访问,就是因为php open_basedir做了限制。
    9. [root@lnmp php-fpm.d]# ls /data/nginx/test.com/
    10. 1.js 1.jss 2.jpg 2.js 3.php admin index.html sleep.php
    11. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I
    12. HTTP/1.1 404 Not Found
    13. Server: nginx/1.17.8
    14. Date: Thu, 19 Aug 2021 02:51:12 GMT
    15. Content-Type: text/html; charset=UTF-8
    16. Connection: keep-alive
    17. X-Powered-By: PHP/5.6.30
    18. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
    19. HTTP/1.1 404 Not Found
    20. Server: nginx/1.17.8
    21. Date: Thu, 19 Aug 2021 02:51:45 GMT
    22. Content-Type: text/html; charset=UTF-8
    23. Connection: keep-alive
    24. X-Powered-By: PHP/5.6.30
    25. ## 把配置文件改为正确的
    26. ## 发现可以正常使用
    27. [root@lnmp php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
    28. php_admin_value[open_basedir]=/data/nginx/test.com:/tmp/
    29. [root@lnmp php-fpm.d]# /etc/init.d/php-fpm restart
    30. Gracefully shutting down php-fpm . done
    31. Starting php-fpm done
    32. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
    33. HTTP/1.1 200 OK
    34. Server: nginx/1.17.8
    35. Date: Thu, 19 Aug 2021 02:57:52 GMT
    36. Content-Type: text/html; charset=UTF-8
    37. Connection: keep-alive
    38. X-Powered-By: PHP/5.6.30
    39. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I
    40. HTTP/1.1 200 OK
    41. Server: nginx/1.17.8
    42. Date: Thu, 19 Aug 2021 02:58:00 GMT
    43. Content-Type: text/html; charset=UTF-8
    44. Connection: keep-alive
    45. X-Powered-By: PHP/5.6.30

    配置错误日志

    1. // 修改配置文件
    2. [root@lnmp php-fpm.d]# vim /usr/local/php-fpm/etc/php.ini
    3. display_errors = Off
    4. log_errors = On
    5. error_log = /usr/local/php-fpm/var/log/php_error.log
    6. ;error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
    7. error_reporting = E_ALL
    8. // 再次将php的配置文件改错
    9. [root@lnmp php-fpm.d]# vim /usr/local/php-fpm/etc/php-fpm.d/www.conf
    10. php_admin_value[open_basedir]=/data/nginx/wwwtest.com:/tmp/
    11. // 这个日志文件不会自动生成,所以我们自己创建一个,并授权。
    12. [root@lnmp php-fpm.d]# touch /usr/local/php-fpm/var/log/php_error.log
    13. [root@lnmp php-fpm.d]# chmod 777 /usr/local/php-fpm/var/log/php_error.log
    14. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
    15. HTTP/1.1 404 Not Found
    16. Server: nginx/1.17.8
    17. Date: Thu, 19 Aug 2021 03:21:22 GMT
    18. Content-Type: text/html; charset=UTF-8
    19. Connection: keep-alive
    20. X-Powered-By: PHP/5.6.30
    21. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I
    22. HTTP/1.1 404 Not Found
    23. Server: nginx/1.17.8
    24. Date: Thu, 19 Aug 2021 03:21:32 GMT
    25. Content-Type: text/html; charset=UTF-8
    26. Connection: keep-alive
    27. X-Powered-By: PHP/5.6.30
    28. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php
    29. No input file specified.
    30. // 查看错误日志,显示open_basedir限制生效,目录不能访问
    31. [root@lnmp php-fpm.d]# cat /usr/local/php-fpm/var/log/php_error.log
    32. [19-Aug-2021 03:21:22 UTC] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/nginx/test.com/3.php) is not within the allowed path(s): (/data/nginx/wwwtest.com:/tmp/) in Unknown on line 0
    33. [19-Aug-2021 03:21:22 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
    34. [19-Aug-2021 03:21:32 UTC] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/nginx/test.com/sleep.php) is not within the allowed path(s): (/data/nginx/wwwtest.com:/tmp/) in Unknown on line 0
    35. [19-Aug-2021 03:21:32 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
    36. [19-Aug-2021 03:21:45 UTC] PHP Warning: Unknown: open_basedir restriction in effect. File(/data/nginx/test.com/sleep.php) is not within the allowed path(s): (/data/nginx/wwwtest.com:/tmp/) in Unknown on line 0
    37. [19-Aug-2021 03:21:45 UTC] PHP Warning: Unknown: failed to open stream: Operation not permitted in Unknown on line 0
    38. // 再次将配置文件修改回来
    39. [root@lnmp php-fpm.d]# cat /usr/local/php-fpm/etc/php-fpm.d/www.conf
    40. [www]
    41. listen = /tmp/php-fcgi.sock
    42. listen.mode = 666
    43. user = php-fpm
    44. group = php-fpm
    45. pm = dynamic
    46. pm.max_children = 50
    47. pm.start_servers = 20
    48. pm.min_spare_servers = 5
    49. pm.max_spare_servers = 35
    50. pm.max_requests = 500
    51. rlimit_files = 1024
    52. request_slowlog_timeout = 1
    53. slowlog = /usr/local/php-fpm/var/log/www-slow.log
    54. php_admin_value[open_basedir]=/data/nginx/test.com:/tmp/
    55. // 重启服务,可以正常使用,也没有产生错误日志。
    56. [root@lnmp php-fpm.d]# /etc/init.d/php-fpm restart
    57. Gracefully shutting down php-fpm . done
    58. Starting php-fpm done
    59. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/sleep.php -I
    60. HTTP/1.1 200 OK
    61. Server: nginx/1.17.8
    62. Date: Thu, 19 Aug 2021 03:25:43 GMT
    63. Content-Type: text/html; charset=UTF-8
    64. Connection: keep-alive
    65. X-Powered-By: PHP/5.6.30
    66. [root@lnmp php-fpm.d]# curl -x127.0.0.1:80 test.com/3.php -I
    67. HTTP/1.1 200 OK
    68. Server: nginx/1.17.8
    69. Date: Thu, 19 Aug 2021 03:25:50 GMT
    70. Content-Type: text/html; charset=UTF-8
    71. Connection: keep-alive
    72. X-Powered-By: PHP/5.6.30