LNMP之Nginx反向代理负载均衡(二)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
LNMP之Nginx反向代理负载均衡(二)
安装必须插件:
yum install gcc-c++ autoconf automake
yum install zlib zlib-devel opensslopenssl--devel pcre pcre-devel
安装nginx:
./configure
make
make install
关闭防火墙或添加配置项:
service iptables stop
chkconfig iptables off
检查配置文件是否正确:
/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
启动nginx:
cd /usr/local/nginx/sbin
./nginx
查询进程号:
ps -ef | grep nginx
停止进程:
/usr/local/nginx/sbin/nginx -s quit
重启:
/usr/local/nginx/sbin/nginx -s reload
测试:
测试端口:netstat -na|grep 80
浏览器中测试:http://ip:80
修改Nginx的配置文件nginx.conf,内容如下,实现反向代理负载均衡:
#user nobody;worker_processes 2;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;events { worker_connections 10240;}
http { include mime.types;default_type application/octet-stream;server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k;client_max_body_size 8m; sendfile on; tcp_nopush on; tcp_nodelay on; upstream 192.168.2.62 { server 192.168.2.62:8081; server 192.168.2.62:8082; } server { listen 80; server_name 192.168.2.62; location / { proxy_pass http://192.168.2.62;
proxy_set_header X-Real-IP $remote_addr;}}}
设置Nginx自动启动,启动脚本如下:
#!/bin/bash# nginx Startup script for the Nginx HTTP Server# chkconfig: - 85 15# description: Nginx is a high-performance web and proxy server.# It has a lot of features, but it’s not for everyone.# processname: nginx# pidfile: /usr/local/nginx/logs/nginx.pid# config: /usr/local/nginx/conf/nginx.confnginxd=/usr/local/nginx/sbin/nginxnginx_config=/usr/local/nginx/ conf/nginx.confRETV AL=0prog=“nginx”# Start nginx daemons functions.start() {if [ -e /us r/local/nginx/logs/nginx.pid ];then echo “nginx already running....” exit 1fi echo -n “Starting $prog: “ $nginxd -c ${nginx_config} RETV AL=$? echo [ $RETV AL = 0 ] && touch /var/lock/subsys/nginx echo -n “nginx starting done”return $RETV AL}# Stop nginx daemons functions.stop() {if [ ! -e /usr/local/nginx/logs/nginx.pid ];then echo “nginx not running....” exit 1fi echo -n “Stopping $prog: “ $nginxd -s quit sleep 2s RETV AL=$? echo [ $RETV AL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid}# See how we were called.case “$1” instart) start ;;stop) stop ;;restart) stop start ;;*) echo $”Usage: $prog {start|stop|restart}” ex it 1esacexit $RETV AL
有兴趣朋友可以了解更多java教程/java/video.shtml。