Nginx端口转发


//利用端口转发,可以实现在通一台服务器上面,根据访问的域名不同,指定到对应的端口后台服务

    upstream dev1 {
        server 127.0.0.1:8480;

    }

    upstream dev2 {
        server 127.0.0.1:8580;

    }

    #dev1端口转发
    server {
        listen       80;
        server_name  kevin.com;
        access_log  logs/book_access.log;
        error_log   logs/book_error.log;

        #将所有请求转发给dev1池的应用处理
        location / {
            #proxy_set_header Host $host;
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://dev1;
        }
    }

    #dev2端口转发
    server {
        listen       80;
        server_name  coco.com;
        access_log  logs/book_access2.log;
        error_log   logs/book_error2.log;

        #将所有请求转发给dev2池的应用处理
        location / {
            #proxy_set_header Host $host;
            #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://dev2;
        }
    }

你可能感兴趣的:(Nginx)