ubuntu20.04部署nginx正向代理服务

12 篇文章 1 订阅

由于默认的nginx发布版本不支持正向代理功能,需要借助ngx_http_proxy_connect_module这个三方插件来完成,具体步骤如下

1、下载nginx源码包,笔者使用的是1.19.10版本,具体下载地址为:Index of /download/

2、安装依赖组件,sudo apt install build-essential openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev

3、下载ngx_http_proxy_connect_module三方组件源码,下载地址为https://github.com/chobits/ngx_http_proxy_connect_module

4、执行命令

patch -p1 < /path/to/ngx_http_proxy_connect_module/patch/proxy_connect.patch

5、执行configure命令

./configure --add-module=/path/to/ngx_http_proxy_connect_module

6、执行make & make install进行编译及安装

7、编译成功后会把nginx放在/usr/local/nginx目录下,其他目录参照nginx官网Building nginx from Sources

8、找到nginx的配置文件,默认为/usr/local/nginx/conf目录,添加如下配置:

server {
                 # 监听端口,这样其他内网机器就可以通过nginx服务器的8888端口访问外网,所以nginx必须能够访问外网
                 listen                         8888;

                 # dns resolver used by forward proxying
                 #resolver    180.76.76.76;
                 resolver 127.0.0.53 ipv6=off;
                 resolver_timeout 30s;
                 # forward proxy for CONNECT request
                 proxy_connect;
                 proxy_connect_allow            443 563;
                 # 10秒对笔者来说有点短,会出现下载超时情况,所以延长至600s
                 proxy_connect_connect_timeout  600s;
                 proxy_connect_read_timeout     600s;
                 proxy_connect_send_timeout     600s;
                 send_timeout 600;

                 # forward proxy for non-CONNECT request
                 location / {
                         proxy_pass http://$host;
                         proxy_set_header Host $host;
                 }
        }

9、启动nginx即可

参照文章:

1、Building nginx from Sources

2、https://github.com/chobits/ngx_http_proxy_connect_module

3、https://github.com/chobits/ngx_http_proxy_connect_module#configuration-example

Ubuntu 20.04上安装Nginx的步骤如下: 1. 首先,更新apt-get源以确保获取最新的软件包列表: ``` sudo apt-get update ``` 2. 安装Nginx: ``` sudo apt-get install nginx ``` 3. 安装完成后,Nginx服务将自动启动。您可以在浏览器中输入服务器的IP地址来查看Nginx的初始页面。 4. 您可以使用以下命令来检查Nginx的安装版本: ``` nginx -v ``` 输出应该类似于:nginx version: nginx/1.18.0 (Ubuntu) 5. 您可以使用systemctl命令来管理Nginx服务: - 查看Nginx服务状态: ``` sudo systemctl status nginx ``` - 启动Nginx服务: ``` sudo systemctl start nginx ``` - 停止Nginx服务: ``` sudo systemctl stop nginx ``` - 重启Nginx服务: ``` sudo systemctl restart nginx ``` 请注意,这些命令需要使用sudo权限。 希望这些信息对您有所帮助! #### 引用[.reference_title] - *1* *3* [Ubuntu20.04安装配置Nginx](https://blog.csdn.net/qq_45951779/article/details/128969250)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [[Nginx] Ubuntu20.04 LTS 安装Nginx](https://blog.csdn.net/qq_19007335/article/details/124539225)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值