反向代理 - 配置

1. 配置语法

Syntax: proxy_pass URL;
Default: -
Context: location, if in action, limit_except

2. 配置代理服务器

[root@VM_0_15_centos code2]# vim /etc/nginx/conf.d/fx_proxy.conf
server {
    listen       80;
    server_name  localhost;

    location / {
        root   /opt/app/code;
        index  index.html index.htm;
    }

    location ~ /test_proxy.html$ {
        proxy_pass http://127.0.0.1:8080;
    }
}

3. 配置被代理(真实)服务器

[root@VM_0_15_centos code2]# vim /etc/nginx/conf.d/realserver.conf
server {
    listen       8080;
    server_name  localhost;

    location / {
        root   /opt/app/code2;
        index  index.html index.htm;
    }
}

4. 重载nginx服务器

nginx -s relead -c /etc/nginx/nginx.conf

5. 查看nginx占用了哪些端口

[root@VM_0_15_centos code2]# netstat -luntp|grep nginx
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      10063/nginx: master 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      10063/nginx: master 

6. 测试

浏览器访问http://119.28.190.215/test_proxy.html,看到8080端口下的test_proxy.html,测试成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值