一、測試環境
web服務器1:192.168.0.11:9000
web服務器2:192.168.0.12:9000
web服務器3:192.168.0.13:9000
web服務器4:192.168.0.14:9000
web服務器5:192.168.0.15:9000
nginx:192.168.0.10
二、安裝nginx
1、下載Nginx
https://nginx.org/download/nginx-1.6.0.tar.gz
2、安裝依賴
[root@nginx ~]# yum -y install pcre pcre-devel zlib zlib-devel
[root@nginx ~]# yum -y install gcc gcc-c++
[root@nginx ~]# yum install -y openssl openssl-devel
3、安裝nginx
[root@nginx ~]# tar -zxvf nginx-1.16.0.tar.gz
[root@nginx ~]# cd nginx-1.16.0
[root@nginx ~]# ./configure && make && make install
3、啓動nginx
[root@nginx ~]# /usr/local/nginx/sbin/nginx
4、配置nginx
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
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 www.bystp.com {
server 192.168.0.11:9000;
server 192.168.0.12:9000;
server 192.168.0.13:9000;
server 192.168.0.14:9000;
server 192.168.0.15:9000;
}
server {
listen 80;
server_name www.bystp.com 192.168.0.10;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://www.bystp.com;
proxy_set_header host www.bystp.com;
root html;
index index.html index.htm;
}
5、重啓nginx
[root@nginx ~]# /usr/local/nginx/sbin/nginx -s reload
6、使用客戶端(192.168.0.100)訪問http://www.bystp.com 頁面打開正常。
7、nginx加一塊網卡eth1(192.168.0.10),重啓nginx後客戶端(192.168.1.100)訪問http://www.bystp.com 頁面打開正常。