一、安装依赖库
yum -y install pcre-devel zlib-devel openssl-devel
二、创建账号
useradd -r -s /sbin/nologin www
三、下载ngingx
下载地址:https://nginx.org/en/download.html
tar -xf nginx-1.16.0.tar.gz
四、配置/编译与安装
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
make && make install
编译参数:
–prefix 编译安装到的软件目录
–user worker进程运行用户
–group worker进程运行用户组
–with-http_ssl_module 支持https 需要 pcel-devel 依赖
–with- http_stub_status_module 基本状态信息显示 查看请求数、连接数等
–with- http_realip_module 定义客户端地址和端口为header头信息常用于反向代理后的真实IP获取
五、启动/停止
cd /usr/local/nginx/
sbin/nginx
启动成功:
停止
sbin/nginx -s stop
六、把Nginx作为系统服务
vim /usr/lib/systemd/system/nginx.service
把下面代码添加进nginx.service
[Unit]
Description=Nginx Web Server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
启动Nginx
systemctl start nginx
七、设置Nginx开机启动
systemctl enable nginx