前言
作为当前应用程序使用最广泛的代理和web服务器,nginx安装几乎是运维工程师必备技能;网络上关于nginx的安装编译和依赖包,写的比较混乱,针对自己安装的过程下面作一下记录
nginx依赖
主要包括编译工具和nginx模块需要的第三方库
# 安装nginx依赖
yum install pcre-devel make zlib zlib-devel gcc-c++ libtool openssl openssl-devel gcc automake pcre -y
下载nginx软件
编译和安装ngnix
配置编译nginx的参数
[root@localhost etc]useradd nginx -s /sbin/nologin -M
[root@localhost etc]tar zxf nginx-1.14.0.tar.gz
[root@localhost etc]cd nginx-1.14.0
[root@localhost etc]./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx-1.14.0/ \
--with-http_ssl_module \
--with-http_sub_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre
编译参数及说明
参数 | 说 明 |
---|---|
–user=nginx | 指定程序运行时的用户 |
–group=nginx | 指定程序运行用户所属组 |
–prefix=/usr/local/nginx-1.14.0 | 指定安装目录 |
–with-http_ssl_module | 使其支持https请求,需要已安装openssl |
–with-http_sub_module | 允许用其他文本替换nginx响应中的一些文本 |
–with-http_stub_status_module | 可以获取自上次以来的工作状态 |
–with-http_gzip_static_module | 在线实时压缩输出数据流 |
–with-pcre | 启用pcre库 |
编译
make && make install
建立软连接
ln -s /usr/local/nginx-1.14.0 /usr/local/nginx
ll /usr/local/nginx
将nginx命令加入到系统目录
cd /usr/bin
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
启动服务并检查
nginx -t
# 检查端口
lsof -i :80
# 检查进程
ps -ef | grep nginx