以前写过一篇 CentOS 编译安装 nginx 并配置缩略图插件,当时的环境是 CentOS 6.x 和 Nginx 1.9.x 。 本次安装的环境为 CentOS 7.2 和 Nginx 1.11.10, 有些配置以前自启动的方式发生了变化, 这里再记录一下。
安装编译安装依赖的类库和包
1 | yum install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel |
下载和解压 Nginx 1.11.10
wget http://nginx.org/download/nginx-1.11.10.tar.gz
tar -xzvf nginx-1.11.10.tar.gz
cd nginx-1.11.10
配置 Nginx 安装选项
这里编译了插件 http_image_filter_module, 来实现图片的处理,采用默认的安装路径进行安装。
1 | ./configure\ |
运行结果如下
1 | [[email protected] nginx-1.11.10]# ./configure\ |
最后的几行是配置的结果, 注意这里的 pid file 那一行,后面配置服务的时候,需要用的到。
安装 Nginx
使用如下命令来安装 nginx 。
1 | make && make install |
配置 systemd Nginx 服务和设置 Nginx 自启动
centos 7 中采用 systemd 来管理系统,我们来为 nginx 创建服务文件,来实现通过 systemd 来管理 nginx 。
创建 systemd 服务文件: /lib/systemd/system/nginx.service
,内容如下:
1 | [Unit] |
这里的 PIDFile 的配置要和前面的 配置保持一致。
设置自启动
1 | systemctl enable nginx |
通过 systemd 管理 nginx
1 | systemctl start nginx |
打完收工。