Centos7 安裝編譯nginx-1.9.6過程

.安裝環境準備

使用編譯安裝nginx最好都先安裝下這些依賴包python

安裝nginx須要的依賴庫linux

yum install -y gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-develnginx

# 下面是對上面依賴包的詳細解析c++

 

1.gcc 安裝

安裝 nginx 須要先將官網下載的源碼進行編譯,編譯依賴 gcc 環境,若是沒有 gcc 環境,則須要安裝:

yum install gcc-c++

2. PCRE pcre-devel 安裝

PCRE(Perl Compatible Regular Expressions) 是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,因此須要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫。nginx也須要此庫。命令:

yum install -y pcre pcre-devel

3. zlib 安裝

zlib 庫提供了不少種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,因此須要在 Centos 上安裝 zlib 庫。

yum install -y zlib zlib-devel

4. OpenSSL 安裝

OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、經常使用的密鑰和證書封裝管理功能及 SSL 協議,並提供豐富的應用程序供測試或其它目的使用。

nginx 不只支持 http 協議,還支持 https(即在ssl協議上傳輸http),因此須要在 Centos 安裝 OpenSSL 庫。

yum install -y openssl openssl-devel
View Code

 

.編譯安裝,啓動nginx

1.下載源碼包

wget -c https://nginx.org/download/nginx-1.9.6.tar.gz

2.解壓縮源碼

tar -zxvf nginx-1.9.6.tar.gz

3.配置,編譯安裝  開啓nginx狀態監測功能

# 設置將nginx 安裝到/opt/nginx196/目錄中正則表達式

cd nginx-1.9.6
./configure --prefix=/opt/nginx196 --with-http_ssl_module --with-http_stub_status_module

nginx的configure參數算法

nginx的configure參數

4.啓動nginx,進入sbin目錄,找到nginx啓動命令

cd /opt/nginx196/sbin
./nginx #啓動
./nginx -s stop #關閉
./nginx -s reload  # 平滑重啓 ,修改了nginx.conf以後,能夠不重啓服務,加載新的配置

5.注意點

此時要檢查兩個防火牆,兩種方式,要麼將其關閉,要麼將80端口開放:sql

通常下面處理方式便可:vim

# 中止 iptables 防火牆安全

service iptables stop  tcp

# 關閉firewalld防火牆
systemctl stop firewalld

關閉selinux:

或者

# iptables開啓80端口

vim /etc/sysconfig/iptables

# 加入以下代碼

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

# firewall開啓80端口

firewall-cmd --permanent --add-port=8000/tcp

firewall-cmd --reload

 

最後關閉selinux:

[root@localhost ~]# getenforce

Enforcing

[root@localhost ~]# setenforce 0

[root@localhost ~]# getenforce

Permissive

永久關閉:

[root@localhost ~]# vim /etc/sysconfig/selinux

SELINUX=enforcing 改成 SELINUX=disabled

 6.查看nginx運行狀態

查看端口是否運行: netstat -tunlp
查看進程是否運行: ps -ef | grep nginx

 

最好使用ip訪問可得下面頁面說明nginx編譯安裝成功

相關文章
相關標籤/搜索