nginx正向代理服务器搭建

更新时间:2023-05-29 06:04:49 阅读: 评论:0

nginx正向代理服务器搭建
nginx正向代理服务器搭建
场景:由于⽹络环境限制,只能通过代理服务器访问外⽹,代理服务器⾃⼰部署、由于业务需求容器或者k8s的pod也需要通过代理访问外⽹
代理服务器搭建:系统CentOS 7,通过编译安装nginx实现正向代理功能
代理服务器(CentOS 7):180. 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 /download/nginx-1.17. && tar -xf nginx-1.17.
git clone /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.rvice
[Unit]
Description=The NGINX HTTP and rever proxy rver
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-ur.target
3、配置nginx代理规则
cp /usr/local/nginx/f  /usr/local/nginx/f.bak
vi  /usr/local/nginx/f
#ur  nobody;
拉雅瀑布worker_process auto;
worker_rlimit_nofile 65535;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
worker_connections  20480;
}
http {
include      pes;
default_type  application/octet-stream;
#log_format  main  '$remote_addr - $remote_ur [$time_local] "$request" '    #                  '$status $body_bytes_nt "$http_referer" '
#                  '"$http_ur_agent" "$http_x_forwarded_for"';
#access_log  logs/access.log  main;
ndfile        on;
#tcp_nopush    on;
#keepalive_timeout  0;
keepalive_timeout  65;
#gzip  on;
rver {
listen      80;
rver_name  localhost;
#chart koi8-r;
#access_log  logs/host.access.log  main;
location / {
root  html;
index  index.html index.htm;
}
#error_page  404              /404.html;
# redirect rver error pages to the static page /50x.html
#
error_page  500 502 503 504  /50x.html;
location = /50x.html {
root  html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
#    proxy_pass  127.0.0.1;
#}
# pass the PHP scripts to FastCGI rver 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
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
#    deny  all;
#}
}
rver {
resolver 8.8.8.8;
listen 8080;
location / {
proxy_pass $http_host$request_uri;
proxy_t_header HOST $http_host;
proxy_buffers 256 4k;
proxy_max_temp_file_size 0k;多彩活动
proxy_connect_timeout 30;
proxy_nd_timeout 60;
proxy_read_timeout 60;
proxy_next_upstream error timeout invalid_header http_502;
}
cho}
rver {
listen                        8443;
# dns resolver ud by forward proxying
resolver                      114.114.114.114;
党员先上# forward proxy for CONNECT request
proxy_connect;
proxy_connect_allow            443 563;
proxy_connect_connect_timeout  10s;
proxy_connect_read_timeout    10s;
proxy_connect_nd_timeout    10s;
# forward proxy for non-CONNECT request
location / {
proxy_pass $host;
proxy_t_header Host $host;
}
}
# another virtual host using mix of IP-, name-, and port-bad configuration    #
#rver {
#    listen      8000;
#    listen      somename:8080;
#    rver_name  somename  alias  another.alias;
#    location / {
#        root  html;
#        index  index.html index.htm;
#    }
#}
# HTTPS rver
#
#rver {
#    listen      443 ssl;
#    rver_name  localhost;
#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;
#    ssl_ssion_cache    shared:SSL:1m;
#    ssl_ssion_timeout  5m;
#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_rver_ciphers  on;
#    location / {
#        root  html;
#        index  index.html index.htm;
#    }
#}
}
#/usr/local/nginx/sbin/nginx -t
#/usr/local/nginx/sbin/nginx -c #/usr/local/nginx/f
#/usr/local/nginx/sbin/nginx -s reload
systemctl enable nginx
systemctl start nginx
内⽹服务器配置代理
1、系统代理
cat /etc/profile  && source /etc/profile
http_proxy=192.168.0.15:8080/
https_proxy=192.168.0.15:8443/
ftp_proxy=192.168.0.15:8080/
export http_proxy
export https_proxy
export ftp_proxy
2、wget代理
cat /etc/wgetrc
http_proxy=192.168.0.15:8080/
https_proxy=192.168.0.15:8443/
ftp_proxy=192.168.0.15:8080/
3、配置apt代理
cat /etc/f  && apt-get update
Acquire::http::proxy "192.168.0.15:8080/";
幼儿园大班安全计划
Acquire::https::proxy "192.168.0.15:8443/";
Acquire::ftp::proxy "ftp://192.168.0.15:8080/";
4、安装docker
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL /docker-ce/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] /docker-ce/linux/ubuntu $(lsb_relea -cs) stable"  apt-get -y update
apt-cache madison docker-ce
apt-get -y install docker-ce=18.06.3~ce~3-0~ubuntu
5、配置docker代理
mkdir -p  /etc/systemd/system/docker.rvice.d/
cat /etc/systemd/system/docker.rvice.f [Service]
Environment="HTTP_PROXY=192.168.0.15:8080" Environment="HTTPS_PROXY=192.168.0.15:8443" Environment="NO_PROXY=*.,."
mkdir .docker
cat .docker/config.json
{
"proxies":
{
关于劳动的手抄报"default":
{
"httpProxy": "192.168.0.15:8080",
"httpsProxy": "192.168.0.15:8443",
"noProxy": "*.,."
}
}
奥数怎么学}
systemctl daemon-reload
systemctl restart docker

本文发布于:2023-05-29 06:04:49,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/89/945288.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:代理   代理服务器   配置   访问   实现
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图