centos7安裝或升級的nginx 轉載

首先上官網下載源碼包,我下載版本是:nginx-1.13.12.tar.gzhtml

而後在/usr/local/src/ 下解壓:nginx

而後三步走:web

第一步:ui

./configure --prefix=/opt/server/nginx/   --user=nginx --group=nginx  --with-this

http_ssl_module    --with-http_stub_status_module   server

注意:這裏須要with什麼模塊,主要就看咱本身的須要,我目前暫時須要htm

--with-http_ssl_module    ip

--with-http_stub_status_modulessl

這兩個模塊,而後開始後面兩步:ci

第二步:

make

第三步:

make install 

安裝成功後,看到在/opt/server/nginx 目錄下已經成功了:

[root@jordy nginx]# pwd

/opt/server/nginx

[root@jordy nginx]# ll

total 16

drwxr-xr-x 2 root root 4096 May 18 17:15 conf

drwxr-xr-x 2 root root 4096 May 18 17:15 html

drwxr-xr-x 2 root root 4096 May 18 17:15 logs

drwxr-xr-x 2 root root 4096 May 18 17:15 sbin

ok,下面咱們能夠啓動nginx:

/opt/server/nginx/sbin/nginx  

啓動成功後查看下服務:

[root@jordy nginx]# ps -ef |grep  nginx | grep -v grep 

root      8947     1  0 17:23 ?        00:00:00 nginx: master process /opt/server/nginx/sbin/nginx

nginx     8948  8947  0 17:23 ?        00:00:00 nginx: worker process

恩,ok了。

而後在server裏面配置上本身的域名:

server {

        listen       80;

        server_name  xxx.xxxx.com;

……

成功後,從新加載nginx ,則執行:

/opt/server/nginx/sbin/nginx  -s reload

成功後訪問咱們的index.html頁,看到:

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

ok,這樣就安裝完畢,下面講講升級的問題;

 

假如咱們的web服務運行了一段時間,因業務發展須要,須要支持http2,這個時候咱們須要用到--with-http_v2_module模塊;或者說咱們須要用到更高版本的nginx,那怎麼辦呢?很簡單,只須要從新按新的需求編譯一份便可,而後把舊的那份./sbin/nginx 替換就ok,而且nginx支持upgrade,具體流程見下面:

首先進入源碼目錄:

cd /usr/local/src/nginx/nginx-1.13.12

而後按新的須要的參數從新編譯一份,注意仍是在/opt/server/nginx目錄下:

    1. ./configure --prefix=/opt/server/nginx   --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module  --with-http_v2_module   

    2. 而後 make不須要make insall  

    3. 而後移走舊的./sbin/nginx   

      mv /opt/server/nginx/sbin/nginx  /opt/server/nginx/sbin/nginx.old  

    4. 而後拷貝當前目錄下cp ./objs/nginx /opt/server/nginx/sbin/nginx來替換舊的

       

      [root@jordy nginx_http_v2]# pwd

      /opt/server/nginx_http_v2

      [root@jordy nginx_http_v2]# ll

      total 16

      drwxr-xr-x 2 root root 4096 May 18 17:36 conf

      drwxr-xr-x 2 root root 4096 May 18 17:36 html

      drwxr-xr-x 2 root root 4096 May 18 17:36 logs

      drwxr-xr-x 2 root root 4096 May 18 17:36 sbin

    5. 而後 運行 make upgrade 

      [root@jordy nginx-1.13.12]# make upgrade 

      /opt/server/nginx/sbin/nginx -t

      nginx: the configuration file /opt/server/nginx/conf/nginx.conf syntax is ok

      nginx: configuration file /opt/server/nginx/conf/nginx.conf test is successful

      kill -USR2 `cat /opt/server/nginx/logs/nginx.pid`

      kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]

      make: *** [upgrade] Error 

    6. 而後查看下升級後的版本以及編譯參數:

      [root@jordy sbin]# ./nginx -V

      nginx version: tang/810

      built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 

      built with OpenSSL 1.0.2k-fips  26 Jan 2017

      TLS SNI support enabled

      configure arguments: --prefix=/opt/server/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_v2_module

      而後就能夠正常使用了;

相關文章
相關標籤/搜索