使用nginx配置多個phpfastcgi負載均衡
使用nginx配置多個php fastcgi負載均衡
伺服器環境是一鍵安裝包lnmp
nginx 配置檔案
參考地址:http://blog.chinaunix.net/uid-26284395-id-3084491.html
nginx 配置檔案
[root@cacti vhost]# cat /usr/local/nginx/conf/vhost/www.test.conf
log_format apilog `$remote_addr $http_x_forwarded_for [$time_local] $http_host $ssl_protocol $request $request_body `
` $request_time $upstream_response_time $status $upstream_status $body_bytes_sent `
` “$http_referer” “$http_user_agent” $upstream_addr`;
upstream fpm-pool {
server 127.0.0.1:9000;
server 127.0.0.1:9001;
keepalive 4;
}
server
{
listen 80;
server_name www.test.com hadxpg.test.com;
index index.html index.htm index.php;
root /var/www/html/mtoyyweb;
#limit_conn crawler 20;
#error_page 404
location ~ .*.(php|php5)?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass fpm-pool;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*.(js|css)?$
{
expires 1h;
}
location /5998153NginxStatus
{
stub_status on;
access_log off;
}
access_log /data/wwwlogs/access_log;
error_log /data/wwwlogs/error.log;
}
[root@cacti vhost]# cat /usr/local/nginx/conf/vhost/fpmstatus.conf
server {
listen 127.0.0.1:15001;
location ~^/fpmstatus$ {
#auth_basic “status page”;
#fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9000;
}
location ~^/fpm2status$ {
#auth_basic “status page”;
#fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
#include fastcgi_params;
include fastcgi.conf;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_pass 127.0.0.1:9001;
}
}
[root@cacti vhost]# cat /usr/local/php/etc/php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /data/wwwlogs/fpm-err.log
log_level = notice
events.mechanism = epoll
;process.priority = -19
[www]
listen = 127.0.0.1:9000
listen.backlog = 65535
listen.allowed_clients = 127.0.0.1
listen.owner = apache
listen.group = apache
listen.mode = 0666
user = apache
group = apache
pm = dynamic
pm.status_path = /fpmstatus
pm.max_children = 1000
pm.start_servers = 48
pm.min_spare_servers = 24
pm.max_spare_servers = 96
access.format = “%R – %u %t %T “%m %r%Q%q” %s %f %d”
access.log = /data/wwwlogs/pool.access.log
request_terminate_timeout = 60
;request_slowlog_timeout = 2
;slowlog = /data/wwwlogs/fpm-slow.log
[root@cacti vhost]# cat /usr/local/php/etc/php-fpm2.conf
[global]
pid = /usr/local/php/var/run/php-fpm2.pid
error_log = /data/wwwlogs/fpm2-err.log
log_level = notice
events.mechanism = epoll
[www]
listen = 127.0.0.1:9001
listen.backlog = 10000
listen.allowed_clients = 127.0.0.1
listen.owner = apache
listen.group = apache
listen.mode = 0666
user = apache
group = apache
pm = dynamic
pm.status_path = /fpm2status
pm.max_children = 1000
pm.start_servers = 48
pm.min_spare_servers = 24
pm.max_spare_servers = 96
request_terminate_timeout = 60
;request_slowlog_timeout = 2
;slowlog = /data/wwwlogs/fpm2-slow.log
測試php-fpm.conf 配置檔案正確性:
[root@cacti vhost]# /usr/local/php/sbin/php-fpm -t -y /usr/local/php/etc/php-fpm2.conf
[01-Jan-2018 19:15:14] NOTICE: configuration file /usr/local/php/etc/php-fpm2.conf test is successful
[root@cacti vhost]# /usr/local/php/sbin/php-fpm -t -y /usr/local/php/etc/php-fpm.conf
[01-Jan-2018 19:15:18] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
[root@cacti vhost]# grep php-fpm2.conf /etc/init.d/php-fpm2
php_fpm_CONF=${prefix}/etc/php-fpm2.conf
[root@cacti vhost]# grep php-fpm.conf /etc/init.d/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
[root@cacti vhost]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@cacti vhost]# /etc/init.d/php-fpm2 restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
開啟錯誤日誌檢視到負載均衡日誌:
[root@cacti vhost]# tail -4 /data/wwwlogs/mtoyy_error.log
2018/01/01 19:12:53 [error] 27486#0: 792819 FastCGI sent in stderr: “PHP message: PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/html/mtoyyweb/include/mysql.class.php on line 24” while reading response header from upstream, client: 61.135.194.48, server: www.uuopp.com, request: “GET /flow_bx.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “www.uuopp.com”, referrer: “http://www.uuopp.com/index.php“
2018/01/01 19:19:02 [error] 27485#0: 792821 FastCGI sent in stderr: “PHP message: PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/html/mtoyyweb/include/mysql.class.php on line 24” while reading response header from upstream, client: 61.135.194.48, server: www.uuopp.com, request: “GET /wapads.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9001”, host: “www.uuopp.com”, referrer: “http://www.uuopp.com/flow_bx.php“
2018/01/01 19:19:03 [error] 27485#0: 792821 FastCGI sent in stderr: “PHP message: PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/html/mtoyyweb/include/mysql.class.php on line 24” while reading response header from upstream, client: 61.135.194.48, server: www.uuopp.com, request: “GET /introduce.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “www.uuopp.com”, referrer: “http://www.uuopp.com/wapads.php“
2018/01/01 19:19:04 [error] 27485#0: 792821 FastCGI sent in stderr: “PHP message: PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /var/www/html/mtoyyweb/include/mysql.class.php on line 24” while reading response header from upstream, client: 61.135.194.48, server: www.uuopp.com, request: “GET /flow_bx.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9001”, host: “www.uuopp.com”, referrer: “http://www.uuopp.com/introduce.php“
本文轉自 wjw555 51CTO部落格,原文連結:http://blog.51cto.com/wujianwei/2056431
相關文章
- 使用Nginx配置TCP負載均衡NginxTCP負載
- nginx配置+uwsgi+負載均衡配置Nginx負載
- Nginx負載均衡配置說明Nginx負載
- nginx讓多個tomcat實現負載均衡NginxTomcat負載
- Nginx多種負載均衡策略搭建Nginx負載
- Nginx/Httpd負載均衡tomcat配置Nginxhttpd負載Tomcat
- NGINX 負載均衡Nginx負載
- 【Nginx】負載均衡Nginx負載
- nginx負載均衡Nginx負載
- 使用nginx進行負載均衡Nginx負載
- 使用nginx負載均衡nodejsNginx負載NodeJS
- Nginx簡單的負載均衡配置示例Nginx負載
- Nginx負載均衡模式Nginx負載模式
- Nginx--負載均衡Nginx負載
- nginx 負載均衡搭建Nginx負載
- Nginx負載均衡策略Nginx負載
- 解析 Nginx 負載均衡Nginx負載
- Nginx專題(2):Nginx的負載均衡策略及其配置Nginx負載
- Nginx 兩臺伺服器配置負載均衡!!!Nginx伺服器負載
- nginx+tomcat負載均衡配置 火推NginxTomcat負載
- docker下nginx反向代理和負載均衡配置DockerNginx負載
- nginx+tomcat反向代理負載均衡配置NginxTomcat負載
- 配置apache和nginx的tomcat負載均衡ApacheNginxTomcat負載
- nginx配置web服務|反向代理|負載均衡NginxWeb負載
- 使用Docker+Nginx模擬負載均衡DockerNginx負載
- Nginx負載均衡詳解Nginx負載
- Nginx負載均衡高可用Nginx負載
- nginx實現負載均衡Nginx負載
- 記錄一次使用docker配置nginx 負載均衡練習DockerNginx負載
- 記一次nginx負載均衡配置情況Nginx負載
- Flume負載均衡配置負載
- apache 負載均衡配置Apache負載
- 【Nginx】Windows平臺下配置Nginx服務實現負載均衡NginxWindows負載
- 【Nginx】Nginx反向代理和負載均衡部署Nginx負載
- Nginx服務系列——負載均衡Nginx負載
- nginx學習之負載均衡Nginx負載
- Nginx 負載均衡原理解讀Nginx負載
- [Open Source] 負載均衡之Nginx負載Nginx