安装依赖
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
官网下载nginx
下载网址:http://nginx.org/en/download.html
http://nginx.org/download/nginx-1.18.0.tar.gz
解压
cd /home
tar -xvf nginx-1.18.0.tar.gz
编译nginx
cd /home/nginx-1.18.0
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-ipv6
make && make install
测试安装是否成功
/usr/local/nginx/sbin/nginx -V
启动nginx服务
cd /usr/local/nginx/sbin
./nginx
验证服务是否启动成功
netstat -ntlp | grep nginx
添加nginx服务
vi /lib/systemd/system/nginx.service
将以下内容插入:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
以服务的方式启动nginx
pkill nginx
systemctl start nginx
查看服务是否启动
systemctl status nginx
配置nginx服务自动启动
systemctl enable nginx
修改配置
配置文件路径:/usr/local/nginx/conf/nginx.conf