站長資訊網
最全最豐富的資訊網站

CentOS 7.3編譯安裝Nginx 1.12.2

1. Nginx簡介
Nginx (發音為[engine x])專為性能優化而開發,其最知名的優點是它的穩定性和低系統資源消耗,以及對并發連接的高處理能力(單臺物理服務器可支持30000~50000個并發連接), 是一個高性能的 HTTP 和反向代理服務器,也是一個IMAP/POP3/SMTP 代理服。

Linux系統:CentOS 7.3

2. 安裝準備
2.1 gcc安裝 

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

[root@nginx ~]# yum -y install gcc-c++

2.2 pcre安裝

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

[root@nginx ~]# yum  -y install  pcre pcre-devel

2.3 zlib安裝

zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,所以需要在 Centos 上安裝 zlib 庫。

[root@nginx ~]# yum -y install zlib zlib-devel

2.4 OpenSSL安裝

OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及 SSL 協議,并提供豐富的應用程序供測試或其它目的使用。
nginx 不僅支持 http 協議,還支持 https(即在ssl協議上傳輸http),所以需要在 Centos 安裝 OpenSSL 庫。

[root@nginx ~]# yum -y install openssl openssl-devel

3. Nginx安裝

3.1 Nginx版本

下載網址:https://nginx.org/en/download.html

CentOS 7.3編譯安裝Nginx 1.12.2

選擇最新的穩定版nginx-1.12.2
版本說明:

Mainline version:Mainline 是 Nginx 目前主力在做的版本,可以說是開發版
Stable version:最新穩定版,生產環境上建議使用的版本
Legacy versions:遺留的老版本的穩定版

3.2 Nginx下載

使用wget命令下載

[root@nginx ~]# wget -c https://nginx.org/download/nginx-1.12.2.tar.gz

如沒有wget命令則安裝:

[root@nginx ~]# yum -y install wget

3.3 解壓

[root@nginx ~]# tar -zxvf nginx-1.12.2.tar.gz

3.4 安裝配置

3.4.1 新建nginx用戶和組

[root@nginx include]# groupadd nginx
[root@nginx include]# useradd -g nginx -d /home/nginx nginx
[root@nginx include]# passwd nginx

3.4.2第三方模塊安裝

本文以安裝第三方模塊sticky為例,版本為1.,2.5,下載地址:

可以到Linux公社資源站下載:

——————————————分割線——————————————

免費下載地址在 http://linux.linuxidc.com/

用戶名與密碼都是www.linuxidc.com

具體下載目錄在 /2018年資料/9月/27日/CentOS 7.3編譯安裝Nginx 1.12.2/

下載方法見 http://www.linuxidc.com/Linux/2013-07/87684.htm

——————————————分割線——————————————

上傳解壓:

[root@nginx ~]# tar -zxvf nginx-goodies-nginx-sticky-module-ng-08a395c66e42..gz
[root@nginx ~]# mv nginx-goodies-nginx-sticky-module-ng-08a395c66e42 nginx-sticky-1.2.5

3.4.3 安裝

[root@nginx ~]# cd nginx-1.12.2
[root@nginx nginx-1.12.2]# ./configure –add-module=/root/nginx-sticky-1.2.5

指定用戶、路徑和模塊配置(可選):

./configure
–user=nginx –group=nginx           #安裝的用戶組
–prefix=/usr/local/nginx           #指定安裝路徑
–with-http_stub_status_module         #監控nginx狀態,需在nginx.conf配置
–with-http_ssl_module             #支持HTTPS
–with-http_sub_module             #支持URL重定向
–with-http_gzip_static_module          #靜態壓縮
–add-module=/root/nginx-sticky-1.2.5          #安裝sticky模塊

3.5 編譯

[root@nginx nginx-1.12.2]# make && make install

報錯:

/root/nginx-sticky-1.2.5//ngx_http_sticky_misc.c: 在函數‘ngx_http_sticky_misc_sha1’中:
/root/nginx-sticky-1.2.5//ngx_http_sticky_misc.c:176:15: 錯誤:‘SHA_DIGEST_LENGTH’未聲明(在此函數內第一次使用)
  u_char hash[SHA_DIGEST_LENGTH];
              ^
/root/nginx-sticky-1.2.5//ngx_http_sticky_misc.c:176:15: 附注:每個未聲明的標識符在其出現的函數內只報告一次
/root/nginx-sticky-1.2.5//ngx_http_sticky_misc.c:176:10: 錯誤:未使用的變量‘hash’ [-Werror=unused-variable]
  u_char hash[SHA_DIGEST_LENGTH];
          ^
/root/nginx-sticky-1.2.5//ngx_http_sticky_misc.c: 在函數‘ngx_http_sticky_misc_hmac_sha1’中:
/root/nginx-sticky-1.2.5//ngx_http_sticky_misc.c:242:15: 錯誤:‘SHA_DIGEST_LENGTH’未聲明(在此函數內第一次使用)
  u_char hash[SHA_DIGEST_LENGTH];

CentOS 7.3編譯安裝Nginx 1.12.2

解決方法:

修改ngx_http_sticky_misc.c文件,新增#include <openssl/sha.h>和#include <openssl/md5.h>模塊

[root@nginx nginx-1.12.2]# sed -i ’12a #include <openssl/sha.h>’ /root/nginx-sticky-1.2.5/ngx_http_sticky_misc.c
[root@nginx nginx-1.12.2]# sed -i ’12a #include <openssl/md5.h>’ /root/nginx-sticky-1.2.5/ngx_http_sticky_misc.c

重新編譯:

[root@nginx nginx-1.12.2]# make && make install

3.6 nginx命令全局執行設置

[root@nginx bin]# cd /usr/local/nginx/sbin/
[root@nginx sbin]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx

4. Nginx相關命令

4.1 版本查看

[root@nginx ~]# nginx  -v
nginx version: nginx/1.12.2

4.2 查看加載的模塊

[root@nginx ~]# nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)
configure arguments: –add-module=/root/nginx-sticky-1.2.5/

4.3 啟停命令

4.3.1 啟動

[root@nginx nginx-1.12.2]# nginx

4.3.2 停止

[root@nginx nginx-1.12.2]# nginx -s stop
[root@nginx nginx-1.12.2]# nginx -s quit

4.3.3 動態加載

[root@nginx nginx-1.12.2]# ngins -s reload

4.3.4 測試配置文件nginx.conf正確性

[root@nginx ~]# nginx  -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

nginx -s quit:此方式停止步驟是待nginx進程處理任務完畢進行停止。
nginx -s stop:此方式相當于先查出nginx進程id再使用kill命令強制殺掉進程。

nginx -s reload:動態加載,當配置文件nginx.conf有變化時執行該命令動態加載。

4.4 開機自啟動

編輯/etc/rc.d/rc.local文件,新增一行/usr/local/nginx/sbin/nginx

[root@nginx rc.d]# cd /etc/rc.d
[root@nginx rc.d]# sed -i ’13a /usr/local/nginx/sbin/nginx’ /etc/rc.d/rc.local
[root@nginx rc.d]# chmod u+x rc.local

5. 更改默認端口

編輯配置文件/usr/local/nginx/conf/nginx.conf,將默認端口80修改為81:

[root@nginx ~]# view /usr/local/nginx/conf/nginx.conf

CentOS 7.3編譯安裝Nginx 1.12.2

加載配置:

[root@nginx ~]# nginx -s reload

6. 訪問Nginx

6.1 關閉防火墻

[root@nginx ~]# firewall-cmd –state
running
[root@nginx ~]# systemctl stop firewalld.service
[root@nginx ~]# firewall-cmd –state
not running

6.2 訪問Nginx

http://localhost:81

CentOS 7.3編譯安裝Nginx 1.12.2

贊(0)
分享到: 更多 (0)
網站地圖   滬ICP備18035694號-2    滬公網安備31011702889846號
八区精品色欲人妻综合网| AAA级久久久精品无码片| 精品99又大又爽又硬少妇毛片| 日韩十八禁一区二区久久| 国产69精品麻豆久久久久| 久久福利资源国产精品999| 亚洲精品视频观看| 99久久99热精品免费观看国产 | 久久国产精品一区二区| 久久精品国产清自在天天线| 成人国产精品一区二区网站| 日韩一区二区三区四区不卡| 国产91精品久久久久久| 国产精品第100页| 色婷婷99综合久久久精品| 无码人妻精品一区二区蜜桃| 亚洲美女精品视频| 久久国产精品只做精品| 久久久久国产精品免费免费不卡| 亚洲av无码乱码国产精品fc2 | 99re九精品视频在线视频| 久久99精品久久久久久青青日本| 久久国产精品久久久| 羞羞色院91精品网站| 亚洲高清专区日韩精品| 国产最新进精品视频| 亚洲精品乱码久久久久久| 一本一本久久aa综合精品| 亚洲精品美女久久久久99| 在线精品亚洲一区二区小说| 久久久99精品一区二区| 九九热这里只有国产精品| 久久露脸国产精品| 水蜜桃精品一二三| 亚洲精品无码午夜福利中文字幕 | 国产精品久久成人影院| 99精品人妻无码专区在线视频区| 国产精品久久永久免费| 亚洲日韩精品无码AV海量| 午夜精品视频任你躁| 国产精品免费视频网站|