首先,前往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.
执行错误信息下面的提示即可,例如下图
![图片[1]-Centos7编译安装Nginx1.20-Rain's Blog](https://cdn.i-f.work/wp-content/uploads/2021/05/20210520104601292.png?imageMogr2/format/webp/)
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掉,重新拉起即可
![图片[2]-Centos7编译安装Nginx1.20-Rain's Blog](https://cdn.i-f.work/wp-content/uploads/2021/05/20210520120241136.png?imageMogr2/format/webp/)
参考资料
- 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博客
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
minimumshen5天前0
微软确实傻逼Lars11天前0
大佬空了整个docker镜像吧,自己安装一直卡在 app_set_config 90GG2个月前0
总结没毛病过客2个月前0
reunion插件是干什么用的?fom3个月前0
你好,请问一下如果用的是QTS5.0自带的反向代理,有什么方法解决吗?amen1233个月前0
服务器也成功搭建了,想咨询下最后防止服务器被黑。是要在XSHELL里头,最后输入/etc/passwd 和/sbin/nologin 吗skyline3个月前0
感谢解释,这个问题要是不想明白,也是永远想不通为什么会这样b1215个月前0
teamspeak@VM-24-13-debian:~$ ./ts3server_startscript.sh start ts3server.pid found, but no server running. Possibly your previously started server crashed Please view the logfile for details. Starting the TeamSpeak 3 server TeamSpeak 3 server started, for details please view the log file 大佬,創了ts服務器卻進不去,這咋辦啊