獲取Nginx軟體包 ==>(文章末尾有腳本一鍵安裝,含獲取軟體包)
官網網站:http://www.nginx.org/社區版或http://www.nginx.com/企業版
原始碼編譯安裝Nginx軟體
回顧原始碼編譯三步走:
① ./configure配置
② make編譯
③ make install安裝
第一步:上傳Nginx軟體包到Linux服務器端
第二步:聯網,安裝Nginx軟體所需的依賴庫
# yum install pcre-devel zlib-devel openssl-devel -y
第三步:對Nginx軟體包進行解壓縮操作
# tar -xf nginx-1.18.0.tar.gz
第四步:創建一個www賬號
# useradd -r -s /sbin/nologin www
第五步:使用./configure對Nginx軟體進行配置(對軟體安裝包進行配置)
# cd nginx-1.18.0
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module
編譯引數說明
引數 作用
–prefix 編譯安裝到的軟體目錄
–user worker行程運行用戶
–group worker行程運行用戶組
–with-http_ssl_module 支持https 需要pcel-devel依賴
第六步:編譯與安裝Nginx軟體
# make && make instal
Nginx目錄介紹
目錄 作用
conf 組態檔(nginx.conf)
html 網站默認目錄(類似apache的htdocs目錄)
logs 日志(access.log、error.log)
sbin 可執行檔案 [軟體的啟動 停止 重啟等]
原生啟動方式:
# sbin/nginx -c /usr/local/nginx/conf/nginx.conf
原生關閉方式:
# sbin/nginx -s stop
原生重啟方式:需要停止Nginx服務,相當于先關閉后打開
# sbin/nginx -s stop
# sbin/nginx -c /usr/local/nginx/conf/nginx.conf
原生的熱多載(不停止Nginx服務,多載nginx.conf組態檔)
# sbin/nginx -s reload
☆ Nginx服務配置
CentOS7.6 配置:
使用前提,必須先把Nginx停止掉!!!!!!!!
# sbin/nginx -s stop
撰寫nginx.service腳本,有了這個腳本,我們就可以使用systemctl對其進行控制了
# vim /usr/lib/systemd/system/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 stop nginx
多載Nginx:
# systemctl reload nginx
開啟啟動與開機不啟動:
# systemctl enable nginx
# systemctl disable nginx
shell腳本安裝Nginx
#!/bin/bash
wget http://nginx.org/download/nginx-1.18.0.tar.gz &>/dev/null
sleep 1
tar -xf nginx-1.18.0.tar.gz &>/dev/null
sleep 1
yum -y install gcc
yum -y install gcc-c++
yum -y install make
yum -y install pcre-devel
yum -y install zlib-devel
yum -y install openssl-devel
sleep 1
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
sleep 1
make && make install
sleep 1
cd /usr/local/nginx
sbin/nginx
ps -ef | grep nginx
#shell腳本就是命令的堆砌
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/81421.html
標籤:其他
上一篇:Linux 磁盤管理
