nginx正向代理
下载ngx_http_proxy_connect_module
根据nginx的版本选择合适的patch
nginx version | enable REWRITE phase | patch |
---|---|---|
1.4.x ~ 1.12.x | NO | proxy_connect.patch |
1.4.x ~ 1.12.x | YES | proxy_connect_rewrite.patch |
1.13.x ~ 1.14.x | NO | proxy_connect_1014.patch |
1.13.x ~ 1.14.x | YES | proxy_connect_rewrite_1014.patch |
1.15.2 | YES | proxy_connect_rewrite_1015.patch |
1.15.4 ~ 1.16.x | YES | proxy_connect_rewrite_101504.patch |
1.17.x ~ 1.18.0 | YES | proxy_connect_rewrite_1018.patch |
1.19.x ~ 1.21.0 | YES | proxy_connect_rewrite_1018.patch |
1.21.1 | YES | proxy_connect_rewrite_102101.patch |
指定patch路径:
patch -p1 < /home/zzf/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch
./configure \
--prefix=/opt/nginx \
--sbin-path=/opt/nginx/sbin/nginx \
--modules-path=/opt/nginx/modules \
--conf-path=/opt/nginx/conf/nginx.conf \
--error-log-path=/opt/nginx/log/error.log \
--http-log-path=/opt/nginx/log/access.log \
--pid-path=/opt/nginx/nginx.pid \
--lock-path=/opt/nginx/nginx.lock \
--http-client-body-temp-path=/opt/nginx/client_temp \
--http-proxy-temp-path=/opt/nginx/proxy_temp \
--http-fastcgi-temp-path=/opt/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/opt/nginx/uwsgi_temp \
--http-scgi-temp-path=/opt/nginx/scgi_temp \
--with-compat \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--add-dynamic-module=/home/zzf/ngx_http_proxy_connect_module/
增加的ngx_http_proxy_connect_module模块路径
编译安装:
make && make install
vim /opt/nginx/conf/nginx.conf
load_module /opt/nginx/modules/ngx_http_proxy_connect_module.so; #配置在http上
server {
resolver 114.114.114.114; #DNS地址
listen 80;
proxy_connect;
proxy_connect_allow all; #代理允许通过的端口
proxy_connect_connect_timeout 10s; #代理超时时间
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
root html;
index index.html index.htm;
proxy_pass $scheme://$host$request_uri;
proxy_set_header HOST $http_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;
}
}
查看nginx访问日志: