centos7安装或升级的nginx 转载

首先上官网下载源码包,我下载版本是:nginx-1.13.12.tar.gz

然后在/usr/local/src/ 下解压:

然后三步走:

第一步:

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

http_ssl_module    --with-http_stub_status_module   

注意:这里需要with什么模块,主要就看咱自己的需要,我目前暂时需要

--with-http_ssl_module    

--with-http_stub_status_module

这两个模块,然后开始后面两步:

第二步:

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

      然后就可以正常使用了;

猜你喜欢

转载自www.cnblogs.com/chenjingxuan/p/9104211.html