接下来都是干货的操作
// 1.在local目录创建nginx 文件夹
mkdir /usr/local/nginx
// 2.在usr处创建一个文件夹负责存放上传下载文件的
mkdir /usr/upload
// 3.在upload 文件夹内,在线下载nginx压缩包
cd /usr/upload
wget http://nginx.org/download/nginx-1.17.6.tar.gz
// 4.将下载的文件解压到nginx文件内
tar -zxvf /usr/local/upload/nginx-1.17.6.tar.gz -C /usr/local/nginx
// 5.安装编译nginx所需要的环境
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
// 6.进入到/usr/local/nginx 进行安装编译
cd /usr/local/nginx
./configure && make && make install
// 7.使用nginx 自带的 程序来启动nginx(不推荐)
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
使用nginx 自带的 程序来启动nginx 命令比较长,而且比较麻烦,每次重启要先kill进程,kill 80端口占用的进程,然后再启动。所以打算用systemctl来启动。
在这个文件夹创建这个nginx的service
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx service
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 stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
改完后执行以下命令:
systemctl daemon-reload
systemctl start nginx
systemctl status nginx