CentOS编译安装nginx

文章目录 收缩

安装依赖

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
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

发表评论

电子邮件地址不会被公开。 必填项已用*标注