说明
- 阿里云服务器一台: Ubuntu22.04、 1核1G、位于日本东京
- nginx版本: v1.23.0
- openssl版本: v3.1.0
download
- nginx v1.23.0: wget nginx.org/download/ng…
- openssl v3.1.0: www.openssl.org/source/
- ngx_http_proxy_connect_module: github.com/chobits/ngx…
解压
tar zxvf nginx-1.23.0.tar.gz
tar zxvf openssl-3.1.0-beta1.tar.gz
安装nginx需要的依赖
apt-get update
apt-get install libpcre3 libpcre3-dev
configure nginx
# cd 到nginx解压后的目录
cd /root/nginx-1.23.0
# 更新 nginx 源码,
patch -p1 < /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_102101.patch
# configure nginx
./configure --prefix=/usr/local/nginx --add-module=/root/ngx_http_proxy_connect_module --with-http_ssl_module --with-openssl=/root/openssl-3.1.0-beta1
install nginx
cd /root/nginx-1.23.0
make && make install
启动nginx
# nginx版本
/usr/local/nginx/sbin/nginx -v
# 启动nginx
/usr/local/nginx/sbin/nginx
更新 nginx 配置
vim /usr/local/nginx/conf/nginx.conf
server {
listen 80;
resolver 8.8.8.8;
proxy_connect;
proxy_connect_allow 443 563;
proxy_connect_connect_timeout 10s;
proxy_connect_data_timeout 10s;
location / {
proxy_pass http://$host;
proxy_set_header Host $host;
}
}
重启 nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
测试正向代理是否生效
# 服务器上测试
curl -x http://127.0.0.1:80 -L https://www.baidu.com
curl -x http://127.0.0.1:80 -L http://www.baidu.com
# 本机测试
curl -x http://47.245.30.201:80 -L http://www.baidu.com
curl -x http://47.245.30.201:80 -L https://www.baidu.com
firefox配置代理测试
- 点击 firefox 设置 > 常规 > 网络设置
-
勾选手动配置代理, http和https代理配置为正向代理的ip和端口
-
下图是我的服务器的地理位置,位于日本东京
-
firefox 在 baidu 搜索ip,可以看到当前ip地址是我的服务器ip,位置是日本东京 阿里云,说明firefox的网络请求经过了服务器的nginx代理服务器