共計 2477 個字符,預計需要花費 7 分鐘才能閱讀完成。
今天丸趣 TV 小編給大家分享一下 centos7 編譯安裝 nginx1.16.0 的方法是什么的相關知識點,內容詳細,邏輯清晰,相信大部分人都還太了解這方面的知識,所以分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后有所收獲,下面我們一起來了解一下吧。
一、安裝依賴包
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
[Servi
ce]
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.servi
ce - nginx Loaded: loaded (/usr/lib/systemd/system/nginx.servi
ce; 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.servi
ce ├─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.servi
ce to /usr/lib/systemd/system/nginx.servi
ce.
以上就是“centos7 編譯安裝 nginx1.16.0 的方法是什么”這篇文章的所有內容,感謝各位的閱讀!相信大家閱讀完這篇文章都有很大的收獲,丸趣 TV 小編每天都會為大家更新不同的知識,如果還想學習更多的知識,請關注丸趣 TV 行業資訊頻道。