正向代理服务器搭建
nginx
正向代理服务器搭建
场景:由于⽹络环境限制,只能通过代理服务器访问外⽹,代理服务器⾃⼰部署、由于业务需求容器或者k8s的pod也需要通过代理访问外
⽹
代理服务器搭建:系统CentOS 7,通过编译安装nginx实现正向代理功能
代理服务器(CentOS 7):180.76.189.xxx 192.168.0.15
内⽹服务器(Ubuntu16.04):192.168.0.150
步骤如下:
1、编译安装nginx
yum -y install gcc gcc-c++ autoconf automake pcre pcre-devel openssl openssl-devel patch git net-tools
mkdir -p /downloads && cd /downloads
wget http://nginx.org/download/nginx-1.17.2.tar.gz && tar -xf nginx-1.17.2.tar.gz
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
cd nginx-1.17.2
patch -p1 </downloads/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch
./configure --add-module=/downloads/ngx_http_proxy_connect_module
make && make install
2、把nginx配置systemctl管理
#cat vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
3、配置nginx代理规则
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
vi /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes auto;
worker_rlimit_nofile 65535;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;