1. 程式人生 > >centos7 中原始碼安裝nginx

centos7 中原始碼安裝nginx

使用nginx有一段時間了,還是有很多東西不懂的,在這裡做一下自己學習過程中的一些整理,能使自己得到提升。

1、環境:centos7 1511  最小化安裝

2、下載nginx,可以在系統中下載,也可以提前下載好,直接上傳到伺服器,都是可以的。

[[email protected] ~]# wget -c http://nginx.org/download/nginx-1.14.1.tar.gz

3、安裝nginx的依賴環境

這裡要重點說明一下,因為我們在編譯nginx的時候需要的模組不一樣,所需要的依賴包也不一樣,這裡我接受我使用的依賴,僅供參考

openssl-devel  這個包是https請求的時候要用到的,主要是提供ssl加密,當然其他的nginx模組也有用到這個依賴的,作用差別不大。

pcre  這個包是pcre的正則,是nginx中的rewirte規則會用到的,當然如果你不是用rewirte模組的話,也是可以不用安裝的

zlib 這個包是啟動壓縮傳輸的時候會用到的,一般也是需要安裝的

[[email protected] ~]# yum -y install pcre-devel openssl-devel zlib-devel

當然,這裡也是需要安裝gcc和gcc-c++編譯器的哦

4、編譯和安裝

解壓到指定的目錄中

[[email protected] ~]# tar -xf nginx-1.14.1.tar.gz -C /usr/local/src/

檢視配置選項

[[email protected] nginx-1.14.1]# ./configure --help

軟體配置

[[email protected] nginx-1.14.1]# ./configure --prefix=/usr/local/nginx  --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-http_stub_status_module

如果只是單純的配置web服務的話 ,其中的--with-stream是不需要新增的,具體的配置還是需要根據你的業務來決定的。

編譯和安裝

[[email protected] nginx-1.14.1]# make &&  make install

5、啟動服務,並新增到開機自啟動

[[email protected] nginx-1.14.1]# cd /usr/local/nginx/sbin/
[[email protected] sbin]# ./nginx 

由於是原始碼安裝,設定開機自啟動的話,需要在相應的檔案中新增

[[email protected] sbin]# cd /etc/rc.d/
[[email protected] rc.d]# vim rc.local
/usr/local/nginx/sbin/nginx  #新增這一行
[[email protected] rc.d]# chmod +x rc.local

6、檢視服務的執行狀態

[[email protected] ~]# ps -ef | grep nginx
root      15971      1  0 19:21 ?        00:00:00 nginx: master process ./nginx
nobody    15972  15971  0 19:21 ?        00:00:00 nginx: worker process

完工。。。。。