一、在nginx默认的web目录 nginx/html 目录下, 创建两个文件夹: web1, web2。 html
二、分别放如index.html文件,web1的内容为 web 1, web2的内容为web 2。nginx
三、在nginx的配置文件 /nginx/conf/nginx.conf 文件中,默认的server{ ... } 段下,加入以下内容:web
server { listen 81; server_name localhost; #access_log logs/host.access.log main; location / { root html/web1; index index.html index.htm; } } server { listen 82; server_name localhost; location / { root html/web2; index index.html index.htm; } } upstream proxy_svrs { server localhost:81 weight=10; server localhost:82 weight=10; } server { listen 90; server_name localhost; location / { proxy_pass http://proxy_svrs; } }
四、此时访问 http://localhost:81 , 出现web1的内容; 访问 http://localhost:82 , 出现web2的内容。 代表两个网站已建好。服务器
五、此时屡次访问 http://localhost:90 , 会交替出现web1和web2的内容, 代表已成功启动反向代理+负载均衡。负载均衡
至此, 实现的在一台nginx服务器上的测试工做。 实际工做中应分别部署在三台服务器中。测试