反向代理远端 单台tomcat 使用ip+端口

1、环境

nginx  10.1.1.161     公网:123.58.251.166

tomcat  10.1.1.103 



2、tomcat 配置


[root@host-10-1-1-103 ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      670/redis-server 12 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      997/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1657/master         
tcp6       0      0 :::8080                 :::*                    LISTEN      4502/java           
tcp6       0      0 :::22                   :::*                    LISTEN      997/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1657/master         
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      4502/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      4502/java           
tcp6       0      0 :::3306                 :::*                    LISTEN      1547/mysqld         
[root@host-10-1-1-103 ~]# curl -I http://127.0.0.1:8080
HTTP/1.1 200 
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Date: Sun, 26 Aug 2018 08:46:53 GMT




3、 nginx配置


[root@host-10-1-1-161 conf.d]# pwd
/etc/nginx/conf.d
[root@host-10-1-1-161 conf.d]# ls
test1.conf  test2.conf  test3.conf

[root@host-10-1-1-161 conf.d]# cat test3.conf 
upstream abc.com {
        server 10.1.1.103:8080 ;
        #server 127.0.0.1:8086 ;
        #ip_hash;
       
}

server {

        listen       8085;
        server_name  127.0.0.1:8085;
        location / {
             #反向代理的地址
             proxy_pass http://abc.com;     
        }
}






4、访问:

[root@host-10-1-1-161 ~]# curl http://127.0.0.1:8085




<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <title>Apache Tomcat/8.5.31</title>
        <link href="favicon.ico" rel="icon" type="image/x-icon" />
        <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
        <link href="tomcat.css" rel="stylesheet" type="text/css" />
    </head>

    <body>
        <div id="wrapper">
            <div id="navigation" class="curved container">
                <span id="nav-home"><a href="http://tomcat.apache.org/">Home</a></span>
                <span id="nav-hosts"><a href="/docs/">Documentation</a></span>
                <span id="nav-config"><a href="/docs/config/">Configuration</a></span>
                <span id="nav-examples"><a href="/examples/">Examples</a></span>
                <span id="nav-wiki"><a href="http://wiki.apache.org/tomcat/FrontPage">Wiki</a></span>
                <span id="nav-lists"><a href="http://tomcat.apache.org/lists.html">Mailing Lists</a></span>
                <span id="nav-help"><a href="http://tomcat.apache.org/findhelp.html">Find Help</a></span>
                <br class="separator" />
            </div>
            <div id="asf-box">
                <h1>Apache Tomcat/8.5.31</h1>
            </div>
            <div id="upper" class="curved container">
                <div id="congrats" class="curved container">
                    <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>
                </div>
                <div id="notice">
                    <img src="tomcat.png" alt="[tomcat logo]" />
                    <div id="tasks">
                        <h3>Recommended Reading:</h3>
                        <h4><a href="/docs/security-howto.html">Security Considerations HOW-TO</a></h4>
                        <h4><a href="/docs/manager-howto.html">Manager Application HOW-TO</a></h4>
                        <h4><a href="/docs/cluster-howto.html">Clustering/Session Replication HOW-TO</a></h4>
                    </div>
                </div>

 

posted @ 2018-11-24 16:04  effortsing  阅读(360)  评论(0编辑  收藏  举报