yum install nginx

修改配置文件
vi /etc/nginx/nginx.conf

输入systemctl status nginx.service 命令,查看服务状态

设置自动启动
systemctl enable nginx

启动
systemctl start nginx

重新加载nginx.config
nginx -s reload

方法2下载tar解压

解压
tar -xvf nginx-1.21.5.tar.gz

安装gcc
yum install gcc-c++
安装pcre pcre-devel
yum install -y pcre pcre-devel
安装zlib
yum install -y zlib zlib-devel
安装OpenSSL。
yum install -y openssl openssl-devel
配置Nginx
cd nginx-1.21.5

./configure --with-http_ssl_module
编译、安装
make && make install
启动
/usr/local/nginx/sbin/nginx

停止

/usr/local/nginx/sbin/nginx -s stop

重新加载配置

/usr/local/nginx/sbin/nginx -s reload

设置开机自启

vi /lib/systemd/system/nginx.service

nginx.service内添加以下内容:
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.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 stop
[Install]
WantedBy=multi-user.target

 

使配置生效

systemctl daemon-reload

设置开机启动

systemctl enable nginx.service




 
posted on 2023-06-21 20:31  沐清风  阅读(24)  评论(0)    收藏  举报