需求一、域名映射
server{
listen 80;
server_name www.dimonho.com;
location / {
proxy_pass http://192.168.1.92:18080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
}
需求二、将dimonho.com自动转发到www.dimonho.com
server{
listen 80;
server_name dimonho.com www.dimonho.com;
if ($host = 'dimonho.com'){
rewrite ^/(.*)$ http://www.dimonho.com/$1 permanent;
}
location / {
proxy_pass http://192.168.1.92:18080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
}
需求三、www.dimonho.com集群负载均衡
upstream dh.com {
server 192.168.1.92:18080 weight=1;
server 192.168.1.94:18080 weight=2;
}
server{
listen 80;
server_name dimonho.com www.dimonho.com;
if ($host = 'dimonho.com'){
rewrite ^/(.*)$ http://www.dimonho.com/$1 permanent;
}
location / {
proxy_pass http://dh.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 100m;
}
}
网友评论