nginx is a web server/reverse proxy server/email server/load balancer software developed by Russians and released under a BSD-like protocol. The platform version has the advantages of less resource consumption and strong concurrent processing capability.
For specific usage scenarios, please refer to: Nginx official reference documentation.
For specific platform versions, see: http://nginx.org/packages/
lab environment:
1, Win7 (192.168.84.1) plus virtual machine CentOS7 (192.168.84.128)
2,Win7下tomcat:apache-tomcat-7.0.68,CentOS7下tomcat:apache-tomcat-7.0.70
3. Install Nginx version in CentOS7: nginx-1.10.1
Install nginx-1.10.1 in CentOS7:
I downloaded the source code compiled version: nginx-1.10.1.tar.gz. To compile and install the stable version, you need to install gcc, gcc-c++, openssl-devel, pcre-devel, zlib-devel , and download pcre-devel, zlib - source of the devel.
1. In the directory after decompressing the nginx source code, execute:
./configure \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --with-zlib=/home/merrick/zlib-1.2.8 \ --with-pcre=/home/merrick/pcre-8.38 \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/
</pre><p></p><pre>
2. Compile and install:
[root@localhost nginx-1.10.1]# make & make install
3, start, stop:
Start: /usr/local/nginx/sbin/nginx
Stop: After finding the nginx main process number (master process), execute kill -QUIT main process number
Configure load balancing:
1. Configure /etc/nginx/nginx.conf (refer to https://www.nginx.com/resources/admin-guide/load-balancer/):
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream backend{ server 192.168.84.128:8080 weight=5 max_fails=2 fail_timeout=600s; server 192.168.84.1:8080 weight=4 max_fails=2 fail_timeout=600s; } server { listen 192.168.84.128:80; server_name localhost; #charset koi8-r; access_log logs/host.access.log main; location / { proxy_pass http://backend; # root html; # index index.html index.htm; } location /NginxStatus { stub_status on; access_log off; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }}
2. Start tomcat under win7 and centos7
3. Visit the 80 homepage of centos7 under win7 to test several times:
You can see that when you access the proxy server nginx, you will randomly go to two web homepages: