一、安裝依賴包
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
依賴包說明:
1、編譯依賴 gcc 環境,所以需要:gcc gcc-c++;
2、PCRE(Perl Compatible Regular Expressions) 是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,所以需要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫,所以需要:pcre pcre-devel ;
3、zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,所以需要在 Centos 上安裝 zlib 庫,所以需要:zlib zlib-devel ;
4、OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及 SSL 協議,并提供豐富的應用程序供測試或其它目的使用。nginx 不僅支持 http 協議,還支持 https(即在ssl協議上傳輸http),所以需要在 Centos 安裝 OpenSSL 庫,所以需要:openssl openssl-devel ;
二、從官網下載安裝包
wget https://nginx.org/download/nginx-1.16.0.tar.gz
三、解壓并安裝
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx
make && make install
四、測試安裝是否成功
[root@localhost ~]# nginx -V nginx version: nginx/1.16.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) configure arguments: --prefix=/usr/local/nginx
五、啟動nginx服務
cd /usr/local/nginx/sbin ./nginx
六、驗證服務是否啟動成功
[root@localhost sbin]# netstat -ntlp | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 349/nginx: master
七、添加nginx服務
vi
將以下內容插入:
[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.target
八、以服務的方式啟動nginx
pkill nginx systemctl start nginx
九、查看服務是否啟動
[root@localhost sbin]# systemctl status nginx ● nginx.service - nginx Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled) Active: active (running) since Mon 2019-04-29 23:19:39 EDT; 18min ago Process: 348 ExecStart=/usr/local/nginx/sbin/nginx (code=exited, status=0/SUCCESS) Main PID: 349 (nginx) Tasks: 2 Memory: 976.0K CGroup: /system.slice/nginx.service ├─349 nginx: master process /usr/local/nginx/sbin/nginx └─350 nginx: worker process Apr 29 23:19:39 localhost.localdomain systemd[1]: Starting nginx... Apr 29 23:19:39 localhost.localdomain systemd[1]: Started nginx.
[root@localhost sbin]# netstat -ntlp | grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 349/nginx: master p
十、配置nginx服務自動啟動
[root@localhost sbin]# systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END