NGINX编译ngx_http_proxy_connect_module
1、下载NGINX(网址:http://nginx.org/download/ 当前文档使用版本为1.22.1)及ngx_http_proxy_connect_module模块
[root@localhost work]# tar xzf nginx-1.22.1.tar.gz
[root@localhost work]# cd nginx-1.22.1
[root@localhost nginx-1.22.1]# git clone https://gitee.com/web_design_of_web_frontend/ngx_http_proxy_connect_module.git
2、下载该模块的补丁包(需要通过打补丁的方式把上述下载的正向代理模块导入到nginx模块的存储目录中)
[root@localhost work]# wget https://gitcode.net/mirrors/chobits/ngx_http_proxy_connect_module/-/archive/master/ngx_http_proxy_connect_module-master.tar.gz
[root@localhost work]# tar xzf ngx_http_proxy_connect_module-master.tar.gz
[root@localhost work]# cd ngx_http_proxy_connect_module-master/patch
注:以下为各补丁包兼容版本
[root@localhost work]# patch -p1 < /root/work/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_102101.patch
注:File to patch处应该填写上方+++后面提示的ngx_http_core_module.c所在的目录(本机所在目录为/root/work/nginx-1.22.1/src/http/ ngx_http_core_module.c)
3、进入到nginx-1.22.1目录下编译nginx
[root@localhost nginx-1.22.1]# ./configure
–prefix=/usr/local/nginx \
–sbin-path=/usr/local/nginx/sbin/nginx
–conf-path=/usr/local/nginx/conf/nginx.conf
–error-log-path=/var/log/nginx/error.log
–http-log-path=/var/log/nginx/access.log
–pid-path=/var/run/nginx.pid
–lock-path=/var/run/nginx.lock
–user=nginx --group=nginx
–http-client-body-temp-path=/var/cache/nginx/client_temp
–http-proxy-temp-path=/var/cache/nginx/proxy_temp
–http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
–http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
–http-scgi-temp-path=/var/cache/nginx/scgi_temp
–with-http_ssl_module
–with-http_realip_module
–with-http_addition_module
–with-http_sub_module
–with-http_dav_module
–with-http_flv_module
–with-http_mp4_module
–with-http_gunzip_module
–with-http_gzip_static_module
–with-http_random_index_module
–with-http_secure_link_module
–with-http_stub_status_module
–with-http_auth_request_module
–with-http_image_filter_module
–with-http_geoip_module
–with-http_slice_module
–with-http_v2_module
–with-threads
–with-stream
–with-stream_ssl_module
–with-mail
–with-mail_ssl_module
–with-file-aio
–with-compat
–add-dynamic-module=./ModSecurity-nginx
–add-dynamic-module=./nginx-rtmp-module
–add-dynamic-module=./nginx-module-vts
–add-dynamic-module=./ngx_http_proxy_connect_module #添加该模块进行编译
[root@localhost nginx-1.22.1]# make
注:做升级或第二次编译处理时,不要做make install 操作,可能会覆盖掉之前的配置,make后直接替换二进制文件
4、替换nginx的二进制文件
[root@localhost objs]# cp /root/work/nginx-1.22.1/objs/nginx /user/local/nginx/sbin/
[root@localhost objs]# cp /root/work/nginx-1.22.1/objs/ngx_http_proxy_connect_module.so /usr/local/nginx/modules/
注:替换二进制文件前,停掉nginx服务,将之前的二进制文件备份到其他目录
5、配置nginx
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
主配置文件内添加:load_module modules/ngx_http_proxy_connect_module.so;
域名配置文件如下:
server {
listen 8848; #对外服务端口
charset utf-8;
resolver 114.114.114.114; #配置DNS解析
client_max_body_size 50m;
access_log /data/log/outer_yunpian.com.log main_json;
proxy_connect; #开启该模块功能
proxy_connect_allow 443 80; #允许通过nginx访问该域名80/443端口
proxy_connect_connect_timeout 10s;
proxy_connect_read_timeout 10s;
proxy_connect_send_timeout 10s;
location / {
proxy_pass $scheme://$http_host$request_uri; #设置代理地址
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto http;
proxy_buffer_size 512k;
proxy_buffers 6 512k;
proxy_busy_buffers_size 512k;
proxy_temp_file_write_size 512k;
}
location ~ /\.ht {
deny all;
}
}
6、启动nginx服务
7、在需要做正向代理的客户端服务器上配置环境变量进行测试
[root@node2 ~]# vi /etc/profile
文章来源:https://www.toymoban.com/news/detail-543402.html
[root@node2 ~]# source /etc/profile
添加:
export http_proxy=http://192.168.1.11:8848
export https_proxy=http://192.168.1.11:8848
以上为nginx服务器IP及其代理端口
或者使用以下命令测试:curl --proxy 192.168.1.11:8848 http://www.yunpian.com
若添加了环境变量,则直接使用curl http://www.yunpian.com进行测试文章来源地址https://www.toymoban.com/news/detail-543402.html
到了这里,关于NGINX编译ngx_http_proxy_connect_module及做正向代理的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!