mkdir -p /usr/local/nginx/logs/web
mkdir -p /usr/local/nginx/conf/vhost
vim /usr/local/nginx/conf/nginx.conf #nginx配置文件
include vhost/*.conf; #添加配置内容
vim /usr/local/nginx/conf/vhost/web.conf #web配置文件
upstream web {
server 192.168.70.101:9991;
server 192.168.70.102:9992;
server 192.168.70.103:9993;
server 192.168.70.104:9994;
}
server {
listen 80;
server_name web.com;
charset utf-8;
#access_log logs/host.access.log main;
location / {
proxy_pass http://web;
proxy_set_header host $host;
access_log /usr/local/nginx/logs/web/access.log;
error_log /usr/local/nginx/logs/web/error.log;
root html;
index index.html index.htm;
}
#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;
}
}
ps:本地解析vim /etc/hosts 添加 192.168.70.100 web.com test.com
上面为负载均衡配置下面为服务器配置.
mkdir -p /usr/local/nginx/logs/web
mkdir -p /usr/local/nginx/conf/vhost
mkdir /usr/local/nginx/html/web
echo "web01" >> /usr/local/nginx/html/web/index.html #########
vim /usr/local/nginx/conf/nginx.conf
include vhost/*.conf;
vim /usr/local/nginx/conf/vhost/web.conf
server {
listen 9991;
server_name web.com;
charset utf-8;
#access_log logs/host.access.log main;
location / {
error_log /usr/local/nginx/logs/web/error.log;
access_log /usr/local/nginx/logs/web/access.log;
root html/web;
index index.html index.htm;
}}
第二个就照着搬
第二个网页
mkdir -p /usr/local/nginx/logs/test
mkdir /usr/local/nginx/html/test
echo "web02" >> /usr/local/nginx/html/test/index.html
vim /usr/local/nginx/conf/vhost/test.conf
server {
listen 9991;
server_name test.com;
charset utf-8;
#access_log logs/host.access.log main;
location / {
error_log /usr/local/nginx/logs/test/error.log;
access_log /usr/local/nginx/logs/test/access.log;
root html/test;
index index.html index.htm;
}}
/usr/local/nginx/sbin/nginx -t