想配置一下Linux下Nginx的反向代理,用来实现负载均衡功能。各种原因耽误了,今天配置了一下,遇到了不少麻烦,但是还是搞定了。
一,先启动nginx和php-cgi
#启动 php-cgi
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 8000 -C 5 -f /usr/bin/php-cgi
#启动 nginx
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx
二,修改配置nginx.conf
upstream myselfx {
server 127.0.0.1:10002;
server 127.0.0.1:10001 weight=5;
}
server
{
listen 10000;
server_name localhost;
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /var/log/apps.log access;
location /
{
# fastcgi_pass 127.0.0.1:8000;
# fastcgi_index index.php;
proxy_pass ;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
client_body_buffer_size 256k;
proxy_connect_timeout 60;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_buffer_size 8k;
proxy_buffers 8 64k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location /NginxStatus
{
stub_status on;
auth_basic "NginxStatus";
auth_basic_user_file /usr/local/nginx/conf/authfile;
}
}