docker安装nginx实现正向代理

2019-04-19  本文已影响0人  Firetheworld

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

原理图如下

image.png

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


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
上一篇 下一篇

猜你喜欢

热点阅读