Nginxポジティブエージェントの構成
3681 ワード
Nginxポジティブエージェントの構成
これまでsquidを使用して順方向エージェント構成を行っていましたが、今日はnginxを使用して順方向エージェント構成を試みます.nginx自体はhttpsプロトコルリクエスト転送をサポートしていませんが、nginxがこの効果を達成するためにはサードパーティモジュールngx_を借りる必要があります.http_proxy_connect_module.
ベース依存のインストール
nginxインストールパッケージのダウンロード
ここでは最新の安定バージョン1.16をダウンロードします.1
ダウンロードngx_http_proxy_connect_module
コンフィギュレーション
ここでダウンロードしたパッケージはすべて/rootディレクトリの下にあります.
コンパイルインストール
デフォルトは
プロキシの設定
httpセグメントに次の内容を追加します.
nginxの起動
けんしゅつ
ローカルエージェントの追加(永続的に追加するには、環境変数にエージェント構成を追加する必要があります)
httpエージェントが成功したかどうかを検出
現れる
httpエージェントが成功したかどうかを検出
現れる
これまでsquidを使用して順方向エージェント構成を行っていましたが、今日はnginxを使用して順方向エージェント構成を試みます.nginx自体はhttpsプロトコルリクエスト転送をサポートしていませんが、nginxがこの効果を達成するためにはサードパーティモジュールngx_を借りる必要があります.http_proxy_connect_module.
ベース依存のインストール
yum -y install pcre-devel zlib-devel gcc gcc+c++ make openssl-devel pcre-devel zlib-devel patch git
nginxインストールパッケージのダウンロード
ここでは最新の安定バージョン1.16をダウンロードします.1
wget http://nginx.org/download/nginx-1.16.1.tar.gz
ダウンロードngx_http_proxy_connect_module
git clone https://github.com/chobits/ngx_http_proxy_connect_module.git
コンフィギュレーション
ここでダウンロードしたパッケージはすべて/rootディレクトリの下にあります.
コンパイルインストール
cd /root
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
patch -p1 < ../ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch
./configure --add-module=../ngx_http_proxy_connect_module
make && make install
デフォルトは
/usr/local/nginx
ディレクトリにインストールされていますプロキシの設定
vi /usr/local/nginx/conf/nginx.conf
httpセグメントに次の内容を追加します.
server {
resolver 8.8.8.8; #dns
listen 8080; #
proxy_connect;
proxy_connect_allow 80 443 563;
location / {
proxy_pass $scheme://$http_host$request_uri; # https
proxy_set_header HOST $host;
proxy_buffers 256 4k;
proxy_max_temp_file_size 0k;
proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_next_upstream error timeout invalid_header http_502;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
nginxの起動
/usr/local/nginx/sbin/nginx
けんしゅつ
ローカルエージェントの追加(永続的に追加するには、環境変数にエージェント構成を追加する必要があります)
# http
export http_proxy=http://127.0.0.1:8080
# https
export http_proxy=http://127.0.0.1:8080
httpエージェントが成功したかどうかを検出
[root@centos-linux nginx]# wget http://baidu.com
現れる
--2020-03-24 10:00:55-- http://baidu.com/
Connecting to 127.0.0.1:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 81 [text/html]
Saving to: 'index.html'
100%[==================================================================================================================================================================>] 81 --.-K/s in 0s
2020-03-24 10:00:55 (5.14 MB/s) - 'index.html' saved [81/81]
httpエージェントが成功したかどうかを検出
wget https://baidu.com
現れる
--2020-03-24 10:02:49-- https://baidu.com/
Connecting to 127.0.0.1:8080... connected.
Proxy request sent, awaiting response... 302 Moved Temporarily
Location: http://www.baidu.com/ [following]
--2020-03-24 10:02:49-- http://www.baidu.com/
Connecting to 127.0.0.1:8080... connected.
Proxy request sent, awaiting response... 200 OK
Length: 2381 (2.3K) [text/html]
Saving to: 'index.html.1'
100%[==================================================================================================================================================================>] 2,381 --.-K/s in 0s
2020-03-24 10:02:51 (154 MB/s) - 'index.html.1' saved [2381/2381]