方式一:yum方式安裝軟件
1、安裝yum軟件
[root@web ~]#yum install yum-utils
2、配置yum源文件
[root@web ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
3、安裝nginx軟件
[root@web ~]#yum install nginx
方式二:編譯安裝軟件
1、檢查基礎依賴包
[root@web ~]# rpm -qa openssl-devel openssl
openssl-1.0.2k-19.el7.x86_64
[root@web ~]# rpm -qa pcre-devel pcre
pcre-8.32-17.el7.x86_64
pcre-devel-8.32-17.el7.x86_64
2、安裝openssl-devel
[root@web ~]# yum install openssl openssl-devel -y
[root@web ~]# rpm -qa openssl-devel openssl
openssl-1.0.2k-19.el7.x86_64
openssl-devel-1.0.2k-19.el7.x86_64
3、安裝Nginx
[root@web ~]# mkdir -p /usr/tools # 創建一個放安裝軟件的目錄
[root@web ~]# cd /usr/tools
[root@web /usr/tools]# wget http://nginx.org/download/nginx-1.16.1.tar.gz # 下載nginx壓縮包
[root@web /usr/tools]# useradd nginx -u 1111 -s /sbin/nologin -M # 創建nginx用戶,服務nginx軟件
[root@web /usr/tools]# tar xf nginx-1.16.1.tar.gz
[root@web /usr/tools]# cd nginx-1.16.1/
[root@web /usr/tools]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module # 指定用戶和用戶組,然後指定路徑,和功能模塊對Nginx進行配置
[root@web /usr/tools]# echo $? # 確認是否成功,0表示成功
[root@web /usr/tools]# make # 編譯Nginx
[root@web /usr/tools]# echo $?
[root@web /usr/tools]# make install # 安裝Nginx
[root@web /usr/tools]# ln -s /usr/local/nginx-1.16.1 /usr/local/nginx
4、 啓動Nginx
[root@web ~]# /usr/local/nginx
5、將路徑加入PATH
[root@web ~]# echo'export PATH="/usr/local/nginx/sbin:$PATH"' >>/etc/profile