Nginx配置
1.root和alias
server { listen 8000; # 1.root配合index使用:会吧/test_1拼接到网址前面 location /test_1 { root /etc/nginx/my_html; index index.html; } # 2.alias配合index使用:会吧/test_2拼接到网址后面 location /test_2 { alias /etc/nginx/my_html; index index.html; } }
2.反向代理
# nginx代理服务器 server { listen 8000; location / { # 要被代理的服务器地址 proxy_pass http://127.0.0.1:8001; } } # 真实的服务器 server { listen 127.0.0.1:8001; location / { root /etc/nginx/my_html; index index.html; } }
3.负载均衡
# 负载均衡 upstream fuzaijunheng { # 1.默认的转发规则-轮询 # server 127.0.0.1:8001; # server 127.0.0.1:8002; # 2.加权轮询(权值默认为1) # server 127.0.0.1:8001; # server 127.0.0.1:8002 weight=2; # 3.请求第一次时那台服务器,以后就是那套服务器 ip_hash; server 127.0.0.1:8001; server 127.0.0.1:8002; } # nginx服务器 server { listen 8000; location / { # 负载均衡的名字 proxy_pass http://fuzaijunheng; } } # 真实服务器1 server { listen 127.0.0.1:8001; location / { root /etc/nginx/my_html; index index_1.html; } } # 真实服务器2 server { listen 127.0.0.1:8002; location / { root /etc/nginx/my_html; index index_2.html; } }