美文网首页
docker安装nginx实现正向代理

docker安装nginx实现正向代理

作者: Firetheworld | 来源:发表于2019-04-19 17:44 被阅读0次

公司服务器由于安全原因,只能使用内部网络,无法对外网进行特定网站访问,找一台能够进行外网访问的服务器,外网访问的服务器安装nginx,使用nginx正向代理实现内部一台有需求的服务器进行外网访问,在进行内网服务器的hosts配置。此正向代理仅支持HTTP,对于https无法使用。

原理图如下

image.png

步骤:
一、docker安装nginx
二、default.conf文件的配置。
三、内网服务器的hosts文件编写。


  • 一、运行nginx,映射80端口,并挂载配置文件。
docker run --name=nginx -p 80:80   -v /etc/nginx/conf.d:/etc/nginx/conf.d  -d nginx

2、配置文件的修改:

server {
    listen       80;                  #监听80,通过80端口访问业务网站
    server_name  api.weixin.qq.com;      #定义服务名称

    location / {
       proxy_pass https://api.weixin.qq.com/;  #配置需要访问的域名
    }
}

server {
    listen       80;              #监听80,通过80端口访问业务网站
    server_name  file.api.weixin.qq.com;    #定义服务名称

    location / {
       proxy_pass http://file.api.weixin.qq.com;  #配置需要访问的域名
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
   #     root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

三、需要访问特定网站的内网服务器配置hosts指向。

vi /etc/hosts
ip  api.weixin.qq.com

相关文章

  • docker安装nginx实现正向代理

    公司服务器由于安全原因,只能使用内部网络,无法对外网进行特定网站访问,找一台能够进行外网访问的服务器,外网访问的服...

  • Nginx正向代理配置

    Nginx配置正向代理支持HTTP和HTTPS转发Nginx本身不支持HTTPS正向代理,需要安装ngx_http...

  • 一、 Nginx相关概念

    1 正向代理 nginx不仅可以做反向代理,实现负载均衡。还能用作正向代理来进行上网等功能。 正向代理:如果把局域...

  • nginx代理,负载均衡以及https配置

    Nginx正向代理和反向代理 大家对Nginx反向代理并不陌生,但是很少有人用过Nginx的正向代理。先来通过一组...

  • showdoc部署

    步骤 下载代码 docker 安装 nginx做反向代理 reload nginx 浏览器访问 http://sh...

  • nginx 反向代理实现负载均衡

    docker 快速安装nginx 设置需要代理的从服务器信息 可填多个 本机nginx配置 /etc/nginx...

  • Nginx 配置(二)

    1. Nginx 负载均衡 1.1 概述 Nginx 作为代理服务器角色, 有正向代理和反向代理 两种. 正向代理...

  • Nginx常用功能以及相关配置

    Nginx 常用的功能: 1、Http正向代理、反向代理 正向代理和反向代理的区别:1、正向代理:类似我们想要访问...

  • Nginx 反向代理与负载均衡

    Nginx特点:反向代理 正向代理说反向代理之前,我们先看看正向代理,正向代理也是大家最常接触的到的代理模式,我们...

  • Nginx 反向代理与负载均衡

    Nginx特点:反向代理 正向代理说反向代理之前,我们先看看正向代理,正向代理也是大家最常接触的到的代理模式,我们...

网友评论

      本文标题:docker安装nginx实现正向代理

      本文链接:https://www.haomeiwen.com/subject/ucwduqtx.html