首先,前往nginx: download下载源码
或者,直接使用wget下载并使用tar解压即可
wget http://nginx.org/download/nginx-1.20.0.tar.gz
tar -xvzf nginx-1.20.0.tar.gz
这次我想额外添加一下Brotli模块,所以再下载一下Brotli
git clone https://github.com/google/ngx_brotli
cd /home/ngx_brotli && git submodule update --init && cd /home/nginx-1.20.0
移动到nginx文件目录,开始编译
差点忘了,如果未安装GCC编译器,则需要先执行
yum install gcc-c++
安装./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module --with-http_realip_module --with-http_gzip_static_module --add-module=/home/ngx_brotli
make && make install
编译完成后,可以添加一个软连接方便直接管理nginx
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
现在,执行nginx
即可启动
添加nginx到systemctl守护
进入/usr/lib/systemd/system,新建编辑文件nginx.service
cd /usr/lib/systemd/system
vi nginx.service
按下列样式编辑
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
然后执行下列命令启动/管理Nginx
systemctl daemon-reload
//重新加载 systemd
systemctl enable nginx
//开机启动nginx
systemctl start nginx
//启动nginx
systemctl restart nginx
//重启nginx
systemctl reload nginx
//重载nginx配置文件
一些碰到的问题:
1../configure: error: the HTTP rewrite module requires the PCRE library.
执行下列命令安装pcre-devel openssl openssl-devel
模块
yum -y install pcre-devel openssl openssl-devel
2./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
执行问题1
的命令即可
3../configure: error: Brotli library is missing from the /usr directory.
执行错误信息下面的提示即可,例如下图
4.nginx: [emerg] getpwnam(“www”) failed
没有添加www用户/用户组,执行下列命令
/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www
4.ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=1/FAILURE)
将Nginx直接kill掉,重新拉起即可
参考资料
- Nginx 开启 Brotli 教程
- nginx编译安装之-./configure 参数详解 – 风一样的小李子 – 博客园 (cnblogs.com)
- nginx启动提示nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)_yufeng_lai的博客-CSDN博客
- 源码编译安装nginx详细步骤 – catlee – 博客园 (cnblogs.com)
- Nginx启动报错整理,报错: ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=1/FAILURE)_李在奋斗的博客-CSDN博客
© 版权声明
文章版权由CC-BY-NC-SA 4.0协议分发共享
THE END
暂无评论内容