Nginx 实现按域名分类转发

通过nginx配置不同的域名来实现转发到不同的tomcat

book.felix.com -> 127.0.0.1:8001
movie.felix.com  ->  127.0.0.1:8002
#配置负载均衡池
#Demo1负载均衡池
upstream book_pool{
    server 127.0.0.1:8001;
}
#Demo2负载均衡池
upstream movie_pool{
    server 127.0.0.1:8002;
}

#Demo1端口转发
server {
    listen       80;
    server_name  book.felix.com;
    access_log logs/book.log;
    error_log logs/book.error;
    
    #将所有请求转发给demo_pool池的应用处理
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://book_pool;
    }
}
#Demo2端口转发
server {
    listen       80;
    server_name  movie.felix.com;
    access_log logs/movie.log;
    error_log logs/movie.error;
    
    #将所有请求转发给demo_pool池的应用处理
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://movie_pool;
    }
}

参考:https://www.cnblogs.com/zhaoyingjie/p/7248678.html

你可能感兴趣的:(nginx)