本文將爲大家介紹在CentOS7系統下安裝Nginx的兩種方式。
一、編譯安裝
1. 安裝編譯安裝所需要的依賴
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
2.下載Nginx
yum install -y wget
wget https://nginx.org/download/nginx-1.14.0.tar.gz
3. 解壓
tar zxf nginx-1.14.0.tar.gz
cd nginx-1.14.0
4. 編譯安裝(默認設置)
./configure
make && make install
5. 查看安裝目錄
whereis nginx
nginx: /usr/local/nginx
啓動Nginx
cd /usr/local/nginx/sbin
./nginx
7. 查看Nginx是否運行
ps -ef | grep -v grep | grep nginx
root 4772 1 0 18:27 ? 00:00:00 nginx: master process ./nginx
nobody 4773 4772 0 18:27 ? 00:00:00 nginx: worker process
vi /usr/local/nginx/conf/nginx.conf
注意:對於編譯安裝來說,任何對於Nginx配置文件的修改,如想使其生效,必須重載Nginx,使用以下命令:
./nginx -s reload
二、yum安裝
1. 安裝
1. 安裝
yum install -y nginx
2. 啓動Nginx並設置開機啓動
systemctl start nginx
systemctl enable nginx
3. 驗證Nginx是否啓動
ps -ef | grep -v grep | grep nginx
root 2195 1 0 20:25 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 2196 2195 0 20:25 ? 00:00:00 nginx: worker process
4. 查看Nginx配置文件
vi /etc/nginx/nginx.conf
5. 對於yum安裝的Nginx來說,要想使配置文件的修改生效,需要重啓Nginx,運行以下命令:
systemctl restart nginx
6. 網頁驗證Nginx是否成功運行。
附linux學習資料