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

        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號
        主站蜘蛛池模板: 久久精品9988| 精品久久久久久亚洲| 久久影院综合精品| 在线电影国产精品| 老司机午夜精品视频资源| 国产精品亚洲综合专区片高清久久久 | 日韩精品久久久久久久电影蜜臀| 国产精品哟女在线观看| 国产精品区免费视频| 一本色道久久综合亚洲精品| 国产精品福利片免费看| 国产精品www| 久久精品毛片免费观看| 四虎成人精品在永久在线| 99久久国产主播综合精品 | 国产91精品一区二区麻豆亚洲| 少妇人妻精品一区二区三区| 久久精品国产72国产精福利| 在线欧美v日韩v国产精品v| 东京热TOKYO综合久久精品| 一本一本久久aa综合精品| 久久久久久久亚洲精品 | 国产成人精品免费视频动漫| 无码囯产精品一区二区免费| 三级国产精品| 精品国产污污免费网站入口| 99热精品久久只有精品| 国产精品一在线观看| 97精品国产91久久久久久| 精品一区二区三区自拍图片区 | 亚洲综合一区二区精品导航| 99久久成人国产精品免费| 国产日韩精品中文字无码| 99精品视频在线| 青青草原精品国产亚洲av| 国产亚洲精品观看91在线| 人妻精品久久无码专区精东影业 | 精品国产毛片一区二区无码 | 久久精品成人免费网站| 国产91精品一区二区麻豆网站| 国产麻豆一精品一AV一免费|