[root@nginx conf.d]# vim /test-01.conf
upstream login {
server 192.168.200.121:80;
}
upstream register {
server 192.168.200.122:80;
}
server {
listen 80;
server_name www.test-01.org;
location /login {
proxy_pass http://login/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /register {
proxy_pass http://register/;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@nginx conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx conf.d]# systemctl reload nginx.service
web-01配置
[root@nginx code]# vim /etc/nginx/conf.d/test-01.conf
server {
listen 80;
server_name www.test-01.org;
root /code/test;
location / {
index index.html;
}
}
[root@nginx code]# mkdir /code/test
[root@nginx code]# echo "login" >> /code/test/index.html
[root@nginx code]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx code]# systemctl reload nginx.service
web-02配置
[root@nginx code]# vim /etc/nginx/conf.d/test-01.conf
server {
listen 80;
server_name www.test-01.org;
root /code/test;
location / {
index index.html;
}
}
[root@nginx code]# mkdir /code/test
[root@nginx code]# echo "register" >> /code/test/index.html
[root@nginx code]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx code]# systemctl reload nginx.service
测试