这篇也收在 aaronlau.me:在 CentOS 7 上从源码编译 Nginx
Nginx 学习笔记 (1) - 从源码安装,并实现开机自启
这篇文章写于 2019 年,距今 7 年。文中的做法和默认值可能已经变化,动手前请对照官方文档。
Part A. 安装
⚠️ 测试系统为 CentOS 7.x,在其他 Linux 发行版的操作略有不同。
准备好编译环境。为行文简洁起见,省去非 root 用户的
sudo赋权命令,下同;yum groupinstall 'Development Tools'
安装依赖:PCRE (for regex)、zlib (for gzip) 和 OpenSSL;
yum install pcre pcre-devel zlib zlib-devel openssl openssl-devel
切换至工作目录,可以是任何路径,本系列文依惯例选定
/usr/local/src;cd /usr/local/src
下载源码,有 mainline 和 stable 之分 (此处查阅新版本),本系列文选择稳定版;
wget https://nginx.org/download/nginx-1.16.1.tar.gz tar zxf nginx-1.16.1.tar.gz cd nginx-1.16.1
编译安装 Nginx,通常是安装到
/usr/local/nginx。Nginx 的模块一般是静态编译,如果需求有变更,都需要修改参数(可借由nginx -V列出现有的)并重编译,暂不讨论动态模块;./configure --with-http_ssl_module --with-http_v2_module --with-http_sub_module make && make install
加入至 systemd 守护进程 (系统服务),实现开机自启;

cd /lib/systemd/system/
wget https://raw.githubusercontent.com/Surfine/Code-Snippets/master/nginx.service
systemctl enable nginx.service
创建软连接 (符号链接) 以方便使用。
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin
Aaron Lau这里的文章写于 2010 年代。现在每天的文字在 aaronlau.me,手上在做的是 AI System 6。
这篇在 aaronlau.me 也有存档版本。去那边读

评论