centos7 安裝nginx
一,需要安裝依賴環境
1,安裝gcc c語音寫的nginx,所有需要
yum install gcc-c++
2,PCRE pcre-devel 安裝 正則表達式需要了
yum install -y pcre pcre-devel
3,安裝zlib 庫,壓縮解壓都需要
yum install -y zlib zlib-devel
4,OpenSSL 安裝 https做的ssl
yum install -y openssl openssl-devel
二,安裝nginx
直接下載.tar.gz
安裝包,地址:https://nginx.org/en/download.html
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
解壓
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
默認配置
./configure
make 編譯
make install 安裝
cd /usr/local/nginx/sbin/
./nginx 啓動
./nginx -s stop 停止
./nginx -s quit 退出
./nginx -s reload 重新加載
最好加入守護進程
nginx加入守護進程
1,創建服務
vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/opt/nginx/sbin/nginx -s reload
ExecStop=/opt/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
[Unit]:服務的說明
Description:描述服務
After:描述服務類別
[Service]服務運行參數的設置
Type=forking是後臺運行的形式
ExecStart爲服務的具體運行命令
ExecReload爲重啓命令
ExecStop爲停止命令
PrivateTmp=True表示給服務分配獨立的臨時空間
注意:啓動、重啓、停止命令全部要求使用絕對路徑
[Install]服務安裝的相關設置,可設置爲多用戶
試文件生效
systemctl daemon-reload
systemctl is-enabled servicename.service #查詢服務是否開機啓動
systemctl enable *.service #開機運行服務
systemctl disable *.service #取消開機運行
systemctl start *.service #啓動服務
systemctl stop *.service #停止服務
systemctl restart *.service #重啓服務
systemctl reload *.service #重新加載服務配置文件
systemctl status *.service #查詢服務運行狀態
systemctl --failed #顯示啓動失敗的服務