nginx负载均衡同时负载多个网站

发布时间:2020-12-25编辑:脚本学堂
nginx负载均衡的配置实例,在nginx下同时负载两个网站项目如何配置,本文分享一段nginx负载均衡的配置文件,需要的朋友参考下。

nginx配置,如下:
 

复制代码 代码示例:

user  3w;
worker_processes  2;

pid/tmp/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';
sendfileon;
#tcp_nopush on;

#keepalive_timeout  0;
keepalive_timeout  65;

gzip  on;

upstream demo_plcxue {
server 127.0.0.1:8080;
}

upstream xunkebao {
server 127.0.0.1:8081;
}

server {
listen   80;
server_name  demo.plcxue.com;
index index.html index.htm index.jsp;

access_log  /opt/3w/logs/nginx/plcxue.log; #设定访问日志的存放路径
error_log   /opt/3w/logs/nginx/plcxue.err;

location ^~ /media/ {
alias /opt/3w/plcxue/current/media/;
}

location ^~ /widgets/ {
alias /opt/3w/plcxue/current/widgets/;
}

location / {
client_max_body_size5m;
proxy_connect_timeout   30;
proxy_pass http://demo_plcxue;
}
}
server {
listen   80;
server_name  sms.xunkebao.com;
index index.html index.htm index.jsp;

access_log  /opt/3w/logs/nginx/xunkebao.log; #设定访问日志的存放路径
error_log   /opt/3w/logs/nginx/xunkebao.err;

location ^~ /media/ {
alias /opt/3w/sms/current/media/;
}

location ^~ /widgets/ {
alias /opt/3w/sms/current/widgets/;
}

location / {
client_max_body_size5m;
proxy_connect_timeout   30;
proxy_pass http://xunkebao;
}
}
}