LNMP's Nginx Load balancer (ii)

Source: Internet
Author: User

Installation must be plugin:

Yum Install gcc-c++ autoconf automake

Yum install zlib zlib-devel opensslopenssl--devel pcre pcre-devel

Install nginx:

./configure

Make

Make install

To turn off the firewall or add configuration items:

Service Iptables Stop

Chkconfig iptables off

Check that the configuration file is correct:

/usr/local/nginx/sbin/nginx-t-c/usr/local/nginx/conf/nginx.conf

start nginx:

Cd/usr/local/nginx/sbin

./nginx

Query process number:

Ps-ef | grep nginx

To stop a process:

/usr/local/nginx/sbin/nginx-s quit

Restart:

/usr/local/nginx/sbin/nginx-s Reload

Test:

Test port:Netstat-na|grep 80

in-browser test:http://ip:80


Modify Nginx configuration file nginx.conf, the content is as follows, implement reverse proxy load balancing:

#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;

}

}

}


Set Nginx to start automatically, the startup script is as follows:


#!/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.conf

Nginxd=/usr/local/nginx/sbin/nginx
Nginx_config=/usr/local/nginx/conf/nginx.conf

Retval=0
Prog= "Nginx"


# Start Nginx daemons functions.

Start () {

if [-e/usr/local/nginx/logs/nginx.pid];then
echo "Nginx already running ..."
Exit 1
Fi

Echo-n "Starting $prog:"
$nginxd-C ${nginx_config}
Retval=$?
Echo
[$RETVAL = 0] && Touch/var/lock/subsys/nginx
Echo-n "Nginx Starting Done"
Return $RETVAL
}


# Stop Nginx daemons functions.

Stop () {

if [!-e/usr/local/nginx/logs/nginx.pid];then
echo "Nginx not running ..."
Exit 1
Fi

Echo-n "Stopping $prog:"
$NGINXD-S quit
Sleep 2s
Retval=$?
Echo
[$RETVAL = 0] && rm-f/var/lock/subsys/nginx/usr/local/nginx/logs/nginx.pid
}


# See how we were called.

Case "$" in

Start

Start
;;

Stop

Stop
;;


Restart

Stop
Start
;;


*)

echo $ "Usage: $prog {Start|stop|restart}"
Exit 1

Esac
Exit $RETVAL



This article is from the It DreamWorks blog, so be sure to keep this source http://fly520.blog.51cto.com/2181586/1695438

LNMP's Nginx Load balancer (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.