反向代理 - 配置

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,测试成功。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容