IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> 编译Nginx源码(windows10及centos7) -> 正文阅读

[系统运维]编译Nginx源码(windows10及centos7)

我是为了更新nginx的openssl,所以才重新编译,版本为nginx-1.22.1及openssl-1.1.1s,不适用openssl3.x

1 windows10

1.1 工具

主要工具是vs2017(其他版本也可)、MSYS2Perl,ActivePerl或Strawberry,我使用的是后者,pcrezlib

我用的都是目前最新版的,这里面是安装openssl模组才需要的

参考文章
nginx官网教程

Microsoft Visual C compiler. Microsoft Visual Studio? 8 and 10 are known to work.
MSYS or MSYS2.
Perl, if you want to build OpenSSL? and nginx with SSL support. For example ActivePerl or Strawberry Perl.
Mercurial client.
PCRE, zlib and OpenSSL libraries sources.

1.2 下载nginx源码及openssl-1.1.1s

注意:Nginx源码一定要到这个地址http://hg.nginx.org/nginx
我下载的是当前最新的稳定版本,你们也可以根据需要下载其他版本。release-1.22.1 tag stable-1.22进去下载。

openssl-1.1.1s

编译过程

编译过程简单,也没什么大坑,有些小问题百度就可以,参考文章

其中configure参数,建议使用官网对应版本的参数,我下面这个是1.22.1的,加了openssl

注意这个参数,objs/lib是下载解压openssl的位置

–with-openssl=objs/lib/openssl-1.1.1s

./configure --prefix=/usr/local/nginx --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_stub_status_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_slice_module --with-pcre --with-mail --with-stream --with-stream_ssl_module --with-stream_realip_module --with-http_ssl_module --with-openssl=objs/lib/openssl-1.1.1s

编译好之后,下载官网最新的nginx-1.20.2.zip,把我们编译的nginx.exe替换进去,这样就得到一个自己编译完整的nginx版本安装包。用命令nginx -t和nginx -V进行检验和参考版本。

2 centos7

windows编译后是个完整安装包,替换配置文件就好,对服务影响不大,centos的话,默认安装的文件夹分布太散了。因此为了尽量不影响业务,采用的方法是编译相同版本的nginx,服务器上面替换执行文件即可。

2.1 安装相关依赖

这里我要编译自己的openssl版本,如果不是得安装,参数后面加上openssl openssl-devel

yum -y install gcc gcc-c++ zlib zlib-devel pcre-devel gcc gcc-c++

2.2 解压nginx-1.22.1.tar.gz及openssl-1.1.1s.tar.gz

我的操作是在opt文件下完成的

tar -zxvf nginx-1.22.1.tar.gz
mkdir -p nginx-1.22.1/objs/lib && tar -zxvf openssl-1.1.1s.tar.gz -C ./nginx-1.22.1/objs/lib

2.3 编译安装

进入nginx目录

cd nginx-1.22.1/
2.3.1 执行configure(若报错,查看报错提示,通常是相关依赖未安装)

这里同样是nginx官网的参数

  • –prefix安装目录(与现有安装目录不同)
  • –with-openssl是openssl解压目录
  • module可视情况添加或删除部分
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/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 --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 --user=nginx --group=nginx --with-compat --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 --with-openssl=objs/lib/openssl-1.1.1s --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

进行make编译,如果没有安装过nginx,可以直接make && make install进行编译安装了。如果是直接安装了,后面就不用看了。

make

编译完成后,在opt/nginx-1.22.1/objs文件里就得到了nginx文件,可以下载下来,到其他服务器使用

2.4 更新nginx版本到1.22.1(生产不建议,直接编译相同版本nginx进行替换比较稳妥)

2.4.1 备份相关配置文件,防止意外(重要!!!)

使用yum升级nginx(如果不能更新,就只能rpm重装最新版)

yum update nginx -y

测试检查和重启nginx

# /usr/sbin/nginx -c /etc/nginx/nginx.conf   #如果未启动则先启动
nginx -t && nginx -s reload   # 重启
ps -ef | grep nginx  # 查看nginx进程
2.4.2 (有问题)备份好配置文件,卸载nginx并重装1.22.1版本
yum remove nginx

rpm -Uvh http://nginx.org/packages/centos/7/x86_64/RPMS/nginx-1.22.1-1.el7.ngx.x86_64.rpm

2.5 替换nginx文件并启动

2.5.1 上传相对应版本的nginx到opt文件夹内并赋予权限
chmod 755 /opt/nginx
2.5.2 备份和替换nginx文件
mv /usr/sbin/nginx /usr/sbin/nginx.bak && mv /opt/nginx /usr/sbin/nginx
2.5.3 测试校验并启动
# /usr/sbin/nginx -c /etc/nginx/nginx.conf   #如果未启动则先启动
nginx -t && nginx -s reload   # 重启
1.4 (有问题)还原备份文件
rm -rf /usr/sbin/nginx && mv /usr/sbin/nginx.bak /usr/sbin/nginx

THE END

1.20.1版本的参数

./configure --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-compat --with-debug --with-file-aio --with-google_perftools_module --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_mp4_module --with-http_perl_module=dynamic --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-http_xslt_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-openssl=objs/lib/openssl-1.1.1s --with-threads --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie
```
  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2022-12-25 11:43:44  更:2022-12-25 11:47:41 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/25 19:23:47-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码