Nginx Reverse Proxy +keepalived

Source: Internet
Author: User
Tags install openssl nginx reverse proxy

System version: D 2.6.32-431.el6.x86_64

Virtual Machines: four units

Environmental readiness: Close selinux; close iptables;

Two Nginx +keepalive have been installed and normal;

The other two nodes of the web work properly;

#为了更好的测试, Web 1: www.22 Web 2:www.23;

Nginx Installation:

Yum Install pcre*-y

Yum Install OpenSSL openssl-devel-y

Useradd-s/sbin/nologin-m Nginx

Wget-q http://nginx.org/download/nginx-1.6.2.tar.gz

./configure--user=nginx--group=nginx--prefix=/application/nginx1.6.2--with-http_stub_status_module--with-http_ Ssl_module

echo $?

Make && make install

echo $?

Ln-s/application/nginx1.6.2//application/nginx

/application/nginx/sbin/nginx


Keepalived Installation:

wget http://www.keepalived.org/software/keepalived-1.1.19.tar.gz

Ln-s/usr/src/kernels/2.6.32-504.1.3.el6.x86_64//usr/src/linux

Yum Install openssl*-y

Yum Install popt*-y

CD keepalived-1.1.19

./configurE

Make

Make install

/bin/cp/usr/local/etc/rc.d/init.d/keepalived/etc/init.d/
/bin/cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
Mkdir/etc/keepalived-p
/bin/cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/
/bin/cp/usr/local/sbin/keepalived/usr/sbin/

etc/init.d/keepalived start

Nginx Reverse Proxy configuration Example :

cd/application/nginx/conf/extra/

      VI upstream01.conf 
        upstream blog_ real_servers {
             #ip_hash;
             server 10.0.0.22:80  weight=15;
             server 10.0.0.23:80  weight=15
       }
        server {
            listen       80;
           server_name  blog.etiantian.org;
           location/{
             Proxy_pass http://blog_real_servers;

#代理多个虚拟主机需添加: Proxy_set_header host $host;


}
}

In the main configuration file nginx.conf the HTTP tag contains the configuration file extra/upstream01.conf;

Include extra/upstream01.conf;

Note: Use Nginx to do reverse proxy when try not to do the web.

An nginx can also proxy multiple websites, using multiple VIPs. for different parsing.

#两台服务器都需要配置

Keepalived configuration:

Vi/etc/keepalived/keepalived.conf

! Configuration File for Keepalived

Global_defs {
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 10.0.0.33
Smtp_connect_timeout 30
router_id lvs_7
}

Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 55
Priority 150
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
10.0.0.33/24
}

}


Start both Nginx and keepalive in case the above configuration is checked correctly

/application/nginx/sbin/nginx-s Reload

/etc/init.d/keepalived restart

Native configuration Hosts file: Resolving VIP domain Names

Test:

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/57/81/wKioL1ScP7KwoJoOAACNJo_vB3E808.jpg "style=" float: none; "title=" 7}{uu07t8d2%wcd%2cmmyyd.jpg "alt=" Wkiol1scp7kwojooaacnjo_vb3e808.jpg "/>


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/57/84/wKiom1ScP5ihJpDTAACJVrlfJZU326.jpg "title="]kb9%) ' @FPE $JX) v]ow@k5p.jpg "alt=" Wkiom1scp5ihjpdtaacjvrlfjzu326.jpg "/>



#如果多次访问为同一台主机, check whether Nginx weight=15 weights have been.


Stop one of the Web services to detect if the domain name can be accessed properly ~

If both Web stops the service at the same time, the access is returned:502 Bad Gateway

Stop the keepalive of one of the hosts and test that the Web service is working correctly.

Complete!



Nginx Reverse Proxy +keepalived

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.