Nginx负载均衡

tar xzvf nginx-1.7.7.tar.gz
cd nginx-1.7.7
./configure –with-http_realip_module –with-http_flv_module –with-http_sub_module –with-http_mp4_module –with-http_stub_status_module
make && make install

配置文件
user nobody;
worker_processes 8;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

pid logs/nginx.pid;

events {
worker_connections 20480;
}

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;
access_log /dev/null main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;
upstream test1 {
server 192.168.1.202:80 weight=1 max_fails=2 fail_timeout=20s;
server 192.168.1.203:80 weight=1 max_fails=2 fail_timeout=20s;
server 192.168.1.204:80 weight=1 max_fails=2 fail_timeout=20s;
server 192.168.1.205:80 weight=1 max_fails=2 fail_timeout=20s;

}

server {
listen 80;
server_name test1.com;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
proxy_pass http://test1/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;
}

location /nginx_status {
stub_status on;
access_log off;
allow 192.168.0.0/16;
deny all;
}
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}

server {
listen 80;
server_name test3.com;
rewrite ^/(.*) http://www.baidu.com/$1 permanent;

}

server {
listen 80;
server_name test4.com;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://www.163.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_404;

}

access_log logs/_access.log main;

}

}

One Reply to “Nginx负载均衡”

发表评论

电子邮件地址不会被公开。 必填项已用*标注