nginx反向代理

 

实验一:

1、实现效果 (1)打开浏览器,在浏览器地址栏输入地址www.123.com,跳转到liunx系统tomcat主页面中

2、准备工作 (1)在liunx系统安装tomcat,使用默认端口8080

  • tomcat安装文件放到liunx系统中,解压 进入tomcat的bin目录中,./startup.sh启动tomcat服务器

    [root@topcheer bin]# sh startup.sh
    Using CATALINA_BASE:   /mnt/apache-tomcat-7.0.70
    Using CATALINA_HOME:   /mnt/apache-tomcat-7.0.70
    Using CATALINA_TMPDIR: /mnt/apache-tomcat-7.0.70/temp
    Using JRE_HOME:        /usr/local/jak/jdk1.8.0_181/jre
    Using CLASSPATH:       /mnt/apache-tomcat-7.0.70/bin/bootstrap.jar:/mnt/apache-tomcat-7.0.70/bin/tomcat-juli.jar
    Tomcat started.
    [root@topcheer bin]#
     

(2)对外开放访问的端口(我处直接关闭防火墙,这边步骤可以跳过) firewall-cmd --add-port=8080/tcp --permanent

firewall-cmd -–reload
查看已经开放的端口号 firewall-cmd --list-all

(3)在windows系统中通过浏览器访问tomcat服务器

(4)具体配置,修改Hosts文件

C:\Windows\System32\drivers\etc

修改配置
 server {
        listen       80;
        server_name  192.168.180.113;
​
        #charset koi8-r;
​
        #access_log  logs/host.access.log  main;
​
        location / {
            root   html;
             proxy_pass   http://127.0.0.1:8080;
            index  index.html index.htm;
        }

重启
[root@topcheer sbin]# ./nginx -s reload
[root@topcheer sbin]#


实验二:

1、实现效果 使用nginx反向代理,根据访问的路径跳转到不同端口的服务中 nginx监听端口为9001,

访问http://192.168.180.113:8888/dev/直接跳转到127.0.0.1:8080 访问http://192.168.180.113:8888/uat/直接跳转到192.168.180.112:8088

2、准备工作 (1)准备两个tomcat服务器,一个8080端口,一个8088端口 (2)创建文件夹和测试页面

3、具体配置 (1)找到nginx配置文件,进行反向代理配置

 server {
        listen       8888;
        server_name  192.168.180.113;
​
        #charset koi8-r;
​
        #access_log  logs/host.access.log  main;
​
        location ~ /dev/ {
            root   html;
            proxy_pass   http://127.0.0.1:8080;
            index  index.html index.htm;
        }
​
        location ~ /uat/ {
            root   html;
            proxy_pass   http://192.168.180.112:8088;
            index  index.html index.htm;
        }
​

测试结果:

 

posted @ 2019-10-28 17:34  天宇轩-王  阅读(192)  评论(0编辑  收藏  举报