ubuntu
nginx一般都需要重新编译
无区别:apt安装与源码安装没有太多区别,区别最多的就是路径,还有源码安装可能已经提前下载有源码,而apt没有需要下载
解释:nginx本体是通过apt install nginx安装,但是需要增加第三方模块,这时候需要去官网按照源码按照对应版本下载(nginx -v查看)(因为nginx增减模块一般都需要重新编译,而apt安装的是已经编译好的,所以此时应该找其源码,增减配置参数,重新编译)
原理:由nginx -V里面的configure配置参数可知道--sbin-path路径(没有出现默认安装在/usr/share/nginx/sbin/nginx)其就是nginx核心二进制文件可执行文件,其是第一次编译安装nginx时出现的,我们并非需要替换它,因为例如nginx -s stop或者systemctl start nginx背后起作用的是/usr/sbin/nginx所以我们需要将其替换为新编译的(在/nginx-18.0/objs/下的nginx文件(make编译后出现))
示例:
目地:让nginx能正向代理https请求;需要第三方库的地址https://github.com/chobits/ngx_http_proxy_connect_module
下载并解压第三方模块:
wget https://gitcode.net/mirrors/chobits/ngx_http_proxy_connect_module/-/archive/master/ngx_http_proxy_connect_module-master.tar.gz tar -zxvf ngx_http_proxy_connect_module-master.tar.gz打补丁(这个需要根据自己的版本选择不同的补丁,自行去上面的地址查看)(此时需要提前cd到nginx-1.18.0目录下)(路径根据自己的来): patch -p1 < /opt/nginx/nginxPatch/ngx_http_proxy_connect_module-master/patch/proxy_connect_rewrite_1018.patch
configure(路径根据自己的来):这个操作为./configure + 你原来在nginx -V(configure参数看到的内容) + --add-module=/opt/user/ngx_http_proxy_connect_module-master
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-KTLRnK/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-module=/opt/nginxPatch/ngx_http_proxy_connect_module-master 编译:make此时nginx核心二进制可执行文件就编译在了objs/nginx(下一步无需make install其是为了根据configure配置创建目录(我们只是需要新编译的nginx))
复制(呼应上面的原理 )(最好先备份失误还可以回滚:cp /usr/sbin/nginx /usr/sbin/nginx.back):cp objs/nginx /usr/sbin/nginx