文章目录
国内安装建议更换阿里云源,文章链接:CentOS 8 更换为阿里云的源
一、版本与备用下载地址
- 系统版本:centos8
- nginx版本:1.17.6
备用下载地址:nginx-1.17.6.tar.gz
二、下载安装包
1、安装依赖环境
1 2 3 4 |
#PCRE是一个Perl库,包括 perl 兼容的正则表达式库。nginx 的 http 模块使用 pcre 来解析正则表达式 # zlib库提供了很多种压缩和解压缩的方式, nginx 使用 zlib 对 http 包的内容进行 gzip yum -y install make gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel |
2、创建nginx运行用户
1 |
useradd -M -s /sbin/nologin nginx |
3、下载nginx包并解压
1 2 3 |
wget http://nginx.org/download/nginx-1.17.6.tar.gz tar zxvf nginx-1.17.6.tar.gz -C /usr/local/src/ cd /usr/local/src/nginx-1.17.6/ |
三、编译安装
1、编译
1 2 3 4 5 6 7 8 9 10 11 12 13 |
./configure --prefix=/usr/local/nginx \ --user=nginx \ --group=nginx \ --with-http_v2_module \ --with-http_ssl_module \ --with-http_sub_module \ --with-http_stub_status_module \ --with-http_gzip_static_module \ --with-http_flv_module \ --with-http_mp4_module \ --with-pcre make && make install |
2、配置环境变量
1 |
vim /etc/profile.d/nginx.sh |
1 |
export PATH=$PATH:/usr/local/nginx/sbin #根据自己的安装目录进行调整 |
加载变量使立即生效,或重新连接服务器
1 |
source /etc/profile |
四、配置启动脚本
1、配置启动脚本
1 |
vim /etc/init.d/nginx #配置启动脚本文件 |
添加以下代码(PATH,DAEMON,CONFIGFILE,PIDFILE根据自己目录进行修改)
2、添加执行权限
1 |
chmod +x /etc/init.d/nginx |
3、设置开机自启动
1 2 |
chkconfig --add nginx chkconfig nginx on |
转载请注明:百分数 » centos8 源码安装nginx
责任声明: 本站一切资源仅用作交流学习,请勿用作商业或违法行为!如造成任何后果,本站概不负责!