美文网首页
编译安装nginx

编译安装nginx

作者: linux_龍 | 来源:发表于2019-08-28 21:05 被阅读0次
    image.png
    [root@web02 ~]# wget -P /app/tools   http://nginx.org/download/nginx-1.16.1.tar.gz
    --2019-08-28 20:02:01--  http://nginx.org/download/nginx-1.16.1.tar.gz
    Resolving nginx.org (nginx.org)... 95.211.80.227, 62.210.92.35, 2001:1af8:4060:a004:21::e3
    Connecting to nginx.org (nginx.org)|95.211.80.227|:80... connected.
    HTTP request sent, awaiting response... 200 OK
    Length: 1032630 (1008K) [application/octet-stream]
    Saving to: ‘/app/tools/nginx-1.16.1.tar.gz.2’
    
    100%[=====================================================>] 1,032,630   46.7KB/s   in 52s    
    
    2019-08-28 20:02:56 (19.3 KB/s) - ‘/app/tools/nginx-1.16.1.tar.gz.2’ saved [1032630/1032630]
    
    解压
    [root@web02 /app/tools]# tar xf nginx-1.16.1.tar.gz 
    
    安装包里的内容
    [root@web02 /app/tools/nginx-1.16.1]# ll
    total 120
    drwxr-xr-x 2 www  www       6 Aug 13 20:51 auto
    -rw------- 1 root root 109056 Aug 28 20:38 CHANGES.ru
    drwxr-xr-x 2 www  www       6 Aug 13 20:51 conf
    -rwxr-xr-x 1 www  www    2502 Aug 13 20:51 configure
    drwxr-xr-x 2 www  www       6 Aug 13 20:51 contrib
    drwxr-xr-x 2 www  www       6 Aug 13 20:51 html
    -rw-r--r-- 1 www  www    1397 Aug 13 20:51 LICENSE
    drwxr-xr-x 2 www  www       6 Aug 13 20:51 man
    -rw-r--r-- 1 www  www      49 Aug 13 20:51 README
    drwxr-xr-x 2 www  www       6 Aug 13 20:51 src
    
    如果已下载nginx 卸载使用--nodeps 删除依赖关系 尽量少使用 yum remove 删除会把相关的软件也都删除
    [root@web01 ~]# rpm -e nginx --nodeps
    
    修改代码
    [root@web01 /app/tools/nginx-1.16.1/src/core]# vim nginx.h
     1 
      2 /*
      3  * Copyright (C) Igor Sysoev
      4  * Copyright (C) Nginx, Inc.
      5  */
      4  * Copyright (C) Nginx, Inc.
      5  */
      6 
      7 
      8 #ifndef _NGINX_H_INCLUDED_
      9 #define _NGINX_H_INCLUDED_
     10 
     11 
     12 #define nginx_version      1016001
     13 #define NGINX_VERSION      "1.16.1"
     14 #define NGINX_VER          "oldboy-wang/" NGINX_VERSION
     15 
     16 #ifdef NGX_BUILD
     17 #define NGINX_VER_BUILD    NGINX_VER " (" NGX_BUILD ")"
    18 #else
     19 #define NGINX_VER_BUILD    NGINX_VER
     20 #endif
     21 
     22 #define NGINX_VAR          "oldboy-wang"
     23 #define NGX_OLDPID_EXT     ".oldbin"
     24 
     25 
     26 #endif /* _NGINX_H_INCLUDED_ */
    修改14 22行
    
    修改代码
    [root@web01 /app/tools/nginx-1.16.1/src/http]# vim ngx_http_header_filter_module.c
     49 static u_char ngx_http_server_string[] = "Server: oldboy-wang" CRLF;
     50 static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
     51 static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;
    修改49行
    
    修改代码
    [root@web01 /app/tools/nginx-1.16.1/src/http]# vim ngx_http_special_response.c
    35 static u_char ngx_http_error_tail[] =
     36 "<hr><center>oldboy-wang</center>" CRLF
     37 "</body>" CRLF
     38 "</html>" CRLF
    修改36行
    
    [root@web01 /app/tools/nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1  --user=nginx --group=nginx --with-http_ssl_module  --with-http_stub_status_module
    checking for OS
     + Linux 3.10.0-957.el7.x86_64 x86_64
    checking for C compiler ... found
     + using GNU C compiler
     + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
    checking for gcc -pipe switch ... found
    checking for -Wl,-E switch ... found
    checking for gcc builtin atomic operations ... found
    checking for C99 variadic macros ... found
    checking for gcc variadic macros ... found
    checking for gcc builtin 64 bit byteswap ... found
    checking for unistd.h ... found
    
    安装nginx依赖库
    [root@web01 /app/tools/nginx-1.16.1]# yum install openssl-devel pcre-devel -y 
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    Could not retrieve mirrorlist https://mirror.webtatic.com/yum/el7/x86_64/mirrorlist error was
    14: curl#7 - "Failed connect to mirror.webtatic.com:443; Connection refused"
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
     * webtatic: uk.repo.webtatic.com
    base                                                                                            | 3.6 kB  00:00:00     
    epel                                                                                            | 5.4 kB  00:00:00     
    extras                                                                                          | 3.4 kB  00:00:00     
    nginx-stable                                                                                    | 2.9 kB  00:00:00     
    updates                                                                                         | 3.4 kB  00:00:00     
    https://us-east.repo.webtatic.com/yum/el7/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to us-east.re
    
    编译安装
    [root@web01 /app/tools/nginx-1.16.1]#  make  && make install
    
    创建软连接
    [root@web01 /app/tools]# ln -s /app/nginx-1.16.1/ /app/nginx
    
    检查语法
    [root@web01 /app/tools]# /app/nginx/sbin/nginx -t
    nginx: the configuration file /app/nginx-1.16.1/conf/nginx.conf syntax is ok
    nginx: configuration file /app/nginx-1.16.1/conf/nginx.conf test is successful
    
    启动nginx
    [root@web01 /app/tools]# /app/nginx/sbin/nginx
    
    查看端口
    [root@web01 /app/tools]# lsof -i:80
    COMMAND   PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
    nginx   15252  root    6u  IPv4 119064      0t0  TCP *:http (LISTEN)
    nginx   15253 nginx    6u  IPv4 119064      0t0  TCP *:http (LISTEN)
    
    查看下目录
    [root@web01 /app/tools]# ll /app/nginx
    lrwxrwxrwx 1 root root 18 Aug 27 11:35 /app/nginx -> /app/nginx-1.16.1/
    [root@web01 /app/tools]# ll /app/nginx/
    total 0
    drwx------ 2 nginx root   6 Aug 27 11:19 client_body_temp
    drwxr-xr-x 2 root  root 333 Aug 28 10:27 conf
    drwx------ 2 nginx root   6 Aug 27 11:19 fastcgi_temp
    drwxr-xr-x 2 root  root  40 Aug 27 11:13 html
    drwxr-xr-x 2 root  root  58 Aug 27 11:19 logs
    lrwxrwxrwx 1 root  root  18 Aug 29 19:33 nginx-1.16.1 -> /app/nginx-1.16.1/
    drwx------ 2 nginx root   6 Aug 27 11:19 proxy_temp
    drwxr-xr-x 2 root  root  36 Aug 29 19:22 sbin
    drwx------ 2 nginx root   6 Aug 27 11:19 scgi_temp
    drwx------ 2 nginx root   6 Aug 27 11:19 uwsgi_temp
    

    相关文章

      网友评论

          本文标题:编译安装nginx

          本文链接:https://www.haomeiwen.com/subject/agzmectx.html