nginx正向代理

正向代理

在这里插入图片描述

服务端 10.0.0.44
客户端 10.0.0.43

1、安装Nginx和模块

yum -y install make zlib zlib-devel gcc-c++ libtool  openssl openssl-devel  wget pcre pcre-devel git
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -xzvf nginx-1.14.2.tar.gz
cd nginx-1.14.2/
patch -p1 <../ngx_http_proxy_connect_module/patch/proxy_connect_1014.patch           #补丁
./configure  --with-http_stub_status_module --with-http_ssl_module --add-module=../ngx_http_proxy_connect_module
make && make install

2、虚拟主机配置

[root@c7-44 ~]# mkdir -p /usr/local/nginx/conf/conf.d/
[root@c7-44 ~]# cat /usr/local/nginx/conf/nginx.conf      #精简  把80 的端口配置去掉 只剩这些
user  nobody;           #任何人
worker_processes  1;
events {
	worker_connections  1024;
}
http {
	include       mime.types;
	default_type  application/octet-stream;
	sendfile        on;
	keepalive_timeout  65;
	include /usr/local/nginx/conf/conf.d/*.conf;      #添加90端口的配置文件

}

[root@c7-44 ~]# cat /usr/local/nginx/conf/conf.d/test.conf
server {
        listen 90;              #端口
        server_name 10.0.0.44;       #一般写dns服务器  也可以直接写ip
        resolver 223.5.5.5;
        proxy_connect;
        proxy_connect_allow            443 563;     # https
        proxy_connect_connect_timeout  10s;
        proxy_connect_read_timeout     10s;
        proxy_connect_send_timeout     10s;
location / {
        proxy_pass http://$host;
        proxy_set_header Host $host;
        }
}
[root@c7-44 ~] /usr/local/nginx/sbin/nginx   #启动nginx
[root@c7-44 conf.d]# ss -lntp|grep nginx             #只剩90端口
LISTEN     0      128          *:90                       *:*                   users:(("nginx",pid=28883,fd=6),("nginx",pid=18229,fd=6))

3.客户端配置

全局的代理设置:

vim /etc/profile
##代理
export http_proxy=http://10.0.0.44:90
export https_proxy=http://10.0.0.44:90
export ftp_proxy=http://10.0.0.44:90
[root@c7-43 ~] source /etc/profile

yum的代理设置:

vim /etc/yum.conf 
proxy=http://http://10.0.0.44:90

wget的代理设置:

vim /etc/wgetrc 
http_proxy=http://10.0.0.44:90
ftp_proxy=http://10.0.0.44:90
vim /etc/resolve.conf
#nameserver 223.5.5.5
#nameserver 223.6.6.6

4.测试代理
方法一:
访问HTTP网站,可以直接这样的方式:

curl ‐I ‐‐proxy 10.0.0.44:90 http://www.baidu.com
curl ‐I ‐‐proxy 10.0.0.44:90 https://www.baidu.com

[root@c7-43 ~]# curl ‐I ‐‐proxy 10.0.0.44:90 http://www.baidu.com
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.14.2</center>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
 ###   44[root@c7-44 conf.d]# tail -f /usr/local/nginx/logs/access.log
 停掉44 的nginx 看看是否有日志访问  或者吧nginx stop  去curl

方法二:

使用浏览器访问

这里使用的是firefox浏览器

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

如何确定访问是不是走的代理那?

可以在浏览器上设置好代理后,然后将你代理的nginx关掉,然后重新打开一个网页,会发现测试不可以访问网站了!!

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云原生解决方案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值