Setup of Nginx load balancing and reverse proxy in CentOS

Source: Internet
Author: User

1: Modify the CentOS command line startup (reduce memory footprint):
Vim/etc/inittab     ID:5: Initdefault:   --Modify 5 to 3  to start the interface using StartX
2: Install JDK
1) Decompression: jdk-7u55-linux-i586.Tar. gz [[email protected] jdk]#Tar-ZXVF jdk-7u55-linux-i586.Tar. GZ2) Copy: [[email protected] jdk]#CP-RF Jdk1.7.0_55//usr/local/JDK3) configuration environment [[email protected] bin]# vim/etc/Profile Final insert: Export java_home=/usr/local/jdk/jdk1.7. 0_79 Export PATH= $JAVA _home/Bin: $PATH4) Refresh configuration file: source/etc/Profile Validation: Java javac
3: Install Tomcat
    1ExtractTar-ZXVF2Authorizedchmodu+x/usr/local/tomcats/tomcat1/apache-tomcat-7.0. -/bin3) Start: After entering the Tomcat directory Bin directory:./startup.SH     4) Open port: vim/etc/sysconfig/iptables5) Turn off the firewall: chkconfig iptables off6) Restart Firewall: Service iptables restart7) Modify port number: Vim conf/Server.xml8) to view the process:PSAux |grepTomcat
4: Install Nginx
    1) Installation Environment:Yum-YInstall GCC-c++Yum-YInstallPcre pcre-develYum-YInstallZlib zlib-develYum-YInstallOpenSSL openssl-devel2ExtractTar-ZXVF nginx-1.8.0.Tar. GZ3MobileMVnginx-1.8.0/usr/local/nginx/4) Create temp directory: var]#mkdir-P temp/Nginx5) Entry directory: CD nginx-1.8.0/6) Modify the parameters:

./--prefix=/usr/local/--pid-path=/var/run/nginx/--lock-path=/var/lock/-- error-log-path=/var/log/nginx/--http-log-path=/var/log/nginx/--with--- http-client-body-temp-path=/var/temp/nginx/--http-proxy-temp-path=/var/temp/nginx/-- http-fastcgi-temp-path=/var/temp/nginx/--http-uwsgi-temp-path=/var/temp/nginx/-- http-scgi-temp-path=/var/temp/nginx/scgi      

 7) Compile the installation: Make         Make Install8) Start: cd/usr/local/nginx/sbin/         ./Nginx9) to view the process:PSAux |grepNginxTen) Quick stop:./nginx-s Stop One) Complete stop:./nginx-S quit this method stop step is to wait for the nginx process to finish processing the task to stop. Recommended Use A) Restart:./nginx-s quit./Nginx -Reload the configuration file:./nginx-s Reload
5: Configure the Virtual host:
1 , Nginx support three kinds of virtual host configuration: IP-based virtual host            domain             -based virtual host Port-based virtual host 2, nginx configuration file structure: Each service is a virtual host

......            events{...            }            http{.....                server{...                }                server{...                }            

3、基于ip的虚拟主机配置: 修改配置文件: vim /usr/local/nginx/nginx-1.8.0/conf/nginx.conf
server{                 ;                 192.168. 31.88 ;                 / {                    root html;                    Index index.html index.htm;                }            }
 4、基于域名的虚拟主机配置:        修改配置文件:vim /usr/local/nginx/nginx-1.8.0/conf/nginx.conf
server{                 ;                server_name www.nginxdns1.com;                 / {                    root html_dns1;                    Index index.html index.htm;                }            }            server{                 ;                server_name www.nginxdns2.com;                 / {                    root html_dns2;                    Index index.html index.htm;                }            }
5、基于端口的虚拟主机配置:        修改配置文件:vim /usr/local/nginx/nginx-1.8.0/conf/nginx.conf        监听端口:netstat -an | grep 80
      server{                 ;                 192.168. 31.88 ;                 / {                    root html_port1;                    Index index.html index.htm;                }            }            server{                 ;                 192.168. 31.88 ;                 / {                    root html_port2;                    Index index.html index.htm;                }            }
6, Nginx Reverse proxy:
Modify hosts:# nginx Reverse proxy environment Test             192.168. 31.88 www.nginxproxy1.com             192.168. 31.88 www.nginxproxy2.com turn on two tomcat in different virtual machines: 192.168. 31.88:8080192.168. 31.89:8081 Modify configuration file
#代理tomcat1服务器 upstream tomcat_server1{server192.168.31.89:8081; } #代理tomcat2服务器 upstream tomcat_server2{server192.168.31.88:8080; } #配置虚拟主机: server{listen the;                server_name www.nginxproxy1.com; Location/{#root html_port1; Proxy_pass http://Tomcat_server1;index index.html index.htm; }} server{Listen the;                server_name www.nginxproxy2.com; Location/{#root html_port2; Proxy_pass http://Tomcat_server2;index index.html index.htm; }            }
7, Nginx load Balancing:
Modify hosts: # Nginx Load Balancing Environment test                  192.168. 31.88 www.nginxbalance.com    Two tomcat in different virtual machines:192.168. 31.88:8080192.168. 31.89:8081     Modify the configuration file:

#代理tomcat2服务器 upstream tomcat_server_pool{server192.168.31.88:8080weight=1; Server192.168.31.89:8081weight=1; } #配置虚拟主机: server{listen the;                server_name www.nginxbalance.com; Location/{#root html_port1; Proxy_pass http://Tomcat_server_pool;index index.html index.htm; }            }
Hosts file configuration: 1:nginx based on domain name environment test

192.168.31.88 www.nginxdns1.com
192.168.31.88 www.nginxdns2.com

2:nginx Reverse proxy environment test

192.168.31.88 www.nginxproxy1.com
192.168.31.88 www.nginxproxy2.com

3:nginx Load Balancing Environment test

192.168.31.88 www.nginxbalance.com

Source: http://blog.csdn.net/liudongdong0909/article/details/51048788

Setup of Nginx load balancing and reverse proxy in CentOS

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.