1. 程式人生 > >原創:Nginx反向代理實戰部署

原創:Nginx反向代理實戰部署

image log nginx反向代理 request 1.8 反向代理 conf 負載 -1

均衡負載服務器 10.0.0.9

[[email protected] conf]# vim nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

upstream server_pools {

## ip_hash;

server 10.0.0.7:80 weight=1 max_fails=3 fail_timeout=10;

server 10.0.0.8:80 weight=1

max_fails=3 fail_timeout=10 ;

}

server {

listen 80;

server_name bbs.etiantian.org;

location / {

proxy_pass http://server_pools;

}

}

}

hosts

[[email protected] conf]# cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.1.5 lb01

172.16.1.6 lb02

172.16.1.7 web02

172.16.1.9 web03

172.16.1.8 web01 bbs.etiantian.org www.etiantian.org

172.16.1.51 db01 db01.etiantian.org

172.16.1.31 nfs01

172.16.1.41 backup

172.16.1.61 m01

web服務器1 10.0.0.7

[[email protected] conf]# cat nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘

‘$status $body_bytes_sent "$http_referer" ‘

‘"$http_user_agent" "$http_x_forwarded_for"‘;

server {

listen 80;

server_name bbs.etiantian.org;

location / {

root html/bbs;

index index.html index.htm;

}

access_log logs/access_bbs.log main;

}

server {

listen 80;

server_name www.etiantian.org;

location / {

root html/www;

index index.html index.htm;

}

access_log logs/access_www.log main;

}

}

hosts

[[email protected] conf]# cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.1.5 lb01

172.16.1.6 lb02

172.16.1.7 web02 bbs.etiantianorg www.etiantian.org blog.etiantian.org

172.16.1.9 web03

172.16.1.8 web01

172.16.1.51 db01 db01.etiantian.org

172.16.1.31 nfs01

172.16.1.41 backup

172.16.1.61 m01

10.0.0.9 bbs.etiantianorg www.etiantian.org blog.etiantian.org

web服務器2 10.0.0.8

[[email protected] conf]# cat nginx.conf

worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

sendfile on;

keepalive_timeout 65;

log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘

‘$status $body_bytes_sent "$http_referer" ‘

‘"$http_user_agent" "$http_x_forwarded_for"‘;

server {

listen 80;

server_name bbs.etiantian.org;

location / {

root html/bbs;

index index.html index.htm;

}

access_log logs/access_bbs.log main;

}

server {

listen 80;

server_name www.etiantian.org;

location / {

root html/www;

index index.html index.htm;

}

access_log logs/access_www.log main;

}

}

hosts

[[email protected] conf]# cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

172.16.1.5 lb01

172.16.1.6 lb02

172.16.1.7 web02

#172.16.1.8 web01 www.etiantian.org bbs.etiantian.org blog.etiantian.org

#172.16.1.9 web03

172.16.1.51 db01 db01.etiantian.org

172.16.1.31 nfs01

172.16.1.41 backup

172.16.1.61 m01

10.0.0.9 www.etiantian.org bbs.etiantian.org blog.etiantian.org etiantian.org

總結

1 兩個web服務器的nginx.conf 必須是一樣的

2兩個web都解析負載均衡服務器

3本地win hosts解析負載均衡服務器

技術分享

原創:Nginx反向代理實戰部署