美文网首页
【一】Nginx的编译

【一】Nginx的编译

作者: Michael_abc | 来源:发表于2019-10-12 15:50 被阅读0次

    前言

    Nginx作为一款高性能web服务器软件,应用广泛,最近学习源码,一探究原理和优秀的设计,用一个软件那就从最基础的编译开始吧。

    预备编译

    首先下载Nginx源码,官网,我下载的是nginx/1.10.3。
    Nginx安装也需要依赖库:gzip需要zlib库,rewrite需要pcre库,ssl需要opensll库。

    ubuntu下

    apt-get install openssl libssl-dev ibpcre3 libpcre3-dev zlib1g-dev 
    

    编译

    运行编译help命令

    ./configure --help
    
     --help                             print this message
    
      --prefix=PATH                      set installation prefix
      --sbin-path=PATH                   set nginx binary pathname
      --modules-path=PATH                set modules path
      --conf-path=PATH                   set nginx.conf pathname
      --error-log-path=PATH              set error log pathname
      --pid-path=PATH                    set nginx.pid pathname
      --lock-path=PATH                   set nginx.lock pathname
    
      --user=USER                        set non-privileged user for
                                         worker processes
      --group=GROUP                      set non-privileged group for
                                         worker processes
    ...
    

    这很长的就是编译参数,根据编译参数能自定义安装模块和路径。

    编译命令

    ./configure --add-module=/opt/app/nginx-1.10.3/addon/echo1 \
        --add-module=/opt/app/nginx-1.10.3/addon/echo2 \
        --add-module=/opt/app/nginx-1.10.3/addon/hello \
        --add-module=/opt/app/nginx-1.10.3/addon/my1 \
        --user=nginx \
        --group=nginx
    

    编译命令可以写很多,根据自己的需要来。

    接下就是make && make install

    事项点

    make时可能会出现如下警告而退出make

    src/http/ngx_http_parse.c: In function 'ngx_http_parse_complex_uri':
    src/http/ngx_http_parse.c:1384:32: warning: this statement may fall through [-Wimplicit-fallthrough=]
     1384 |                 r->plus_in_uri = 1;
          |                 ~~~~~~~~~~~~~~~^~~
    src/http/ngx_http_parse.c:1385:13: note: here
     1385 |             default:
          |             ^~~~~~~
    src/http/ngx_http_parse.c:1425:32: warning: this statement may fall through [-Wimplicit-fallthrough=]
     1425 |                 r->plus_in_uri = 1;
          |                 ~~~~~~~~~~~~~~~^~~
    src/http/ngx_http_parse.c:1426:13: note: here
     1426 |             default:
          |             ^~~~~~~
    src/http/ngx_http_parse.c:1472:32: warning: this statement may fall through [-Wimplicit-fallthrough=]
     1472 |                 r->plus_in_uri = 1;
          |                 ~~~~~~~~~~~~~~~^~~
    

    解决办法:在目录auto/gcc文件下找到174-178行删除-Werror

    
    # stop on warning
    CFLAGS="$CFLAGS -Werror"
    
    # debug
    CFLAGS="$CFLAGS -g"
    

    相关文章

      网友评论

          本文标题:【一】Nginx的编译

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