準備
- centos7.8伺服器一台
修改主機名
# hostnamectl set-hostname nginxhost
安裝所需插件
1、安裝gcc
gcc是linux下的編譯器在此不多做解釋,感興趣的小夥伴可以去查一下相關資料,它可以編譯 C,C++,Ada,Object C和Java等語言
安裝指令:
# yum -y install gcc
2、安裝pcre、pcre-devel
pcre是一個perl庫,包括perl相容的正規表達式庫,nginx的http子產品使用pcre來解析正規表達式,是以需要安裝pcre庫。
安裝指令:
# yum install -y pcre pcre-devel
3、安裝zlib
zlib庫提供了很多種壓縮和解壓縮方式nginx使用zlib對http包的内容進行gzip,是以需要安裝
# yum install -y zlib zlib-devel
4、安裝
openssl
openssl是web安全通信的基石,沒有openssl,可以說我們的資訊都是在裸奔。。。。。。
# yum install -y openssl openssl-devel
安裝nginx
1、下載下傳nginx安裝包
# cd /opt
# wget http://nginx.org/download/nginx-1.19.6.tar.gz
2、把壓縮包解壓
# tar -zxf nginx-1.19.6.tar.gz
3、編譯安裝
執行三個指令:
# cd nginx-1.19.6
# ./configure
# make
# make install
4、啟動nginx服務
啟動nginx指令:
# /usr/local/nginx/sbin/nginx
5、檢視nginx服務是否啟動成功
# ps -elf|grep nginx
1 S root 7628 1 0 80 0 - 5143 sigsus 11:20 ? 00:00:00 nginx: master process ./nginx
5 S nobody 7629 7628 0 80 0 - 5252 ep_pol 11:20 ? 00:00:00 nginx: worker process
0 S root 7635 4903 0 80 0 - 28203 pipe_w 11:25 pts/0 00:00:00 grep --color=auto nginx
6、通路http://
172.22.3.164
顯示
7、停止nginx服務
# /usr/local/nginx/sbin/nginx -s stop
配置nginx自啟動
1、建立service
# vi /usr/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.targe
2、設定自啟動
# systemctl daemon-reload
# systemctl enable nginx
nginx啟停指令
# systemctl restart nginx
# systemctl start nginx
# systemctl stop nginx