关于Nginx 1.22-stable源码构建,如何启用所有原始include模块?特别是“ngx_http_log_module”

问题描述 投票:0回答:1

所有,我从https://nginx.org/en/download.html下载了nginx-1.22.1.tar.gz,并打算配置“ngx_http_log_module”的http模块用于日志分析目的,但是不幸的是,该模块似乎没有像我预期的那样工作。

源码包中原来包含的http模块如下:

[root@centos-7-2 nginx-1.22.1]# ls -al src/http/modules/
total 1712
drwxr-xr-x 3 1001 1001   4096 Mar 12 20:24 .
drwxr-xr-x 4 1001 1001   4096 Mar 12 20:24 ..
-rw-r--r-- 1 1001 1001  11866 Oct 19 16:02 ngx_http_access_module.c
-rw-r--r-- 1 1001 1001   6994 Oct 19 16:02 ngx_http_addition_filter_module.c
-rw-r--r-- 1 1001 1001  11742 Oct 19 16:02 ngx_http_auth_basic_module.c
-rw-r--r-- 1 1001 1001  11525 Oct 19 16:02 ngx_http_auth_request_module.c
-rw-r--r-- 1 1001 1001  31112 Oct 19 16:02 ngx_http_autoindex_module.c
-rw-r--r-- 1 1001 1001  19921 Oct 19 16:02 ngx_http_browser_module.c
-rw-r--r-- 1 1001 1001  41078 Oct 19 16:02 ngx_http_charset_filter_module.c
-rw-r--r-- 1 1001 1001   8737 Oct 19 16:02 ngx_http_chunked_filter_module.c
-rw-r--r-- 1 1001 1001  32273 Oct 19 16:02 ngx_http_dav_module.c
-rw-r--r-- 1 1001 1001   6240 Oct 19 16:02 ngx_http_degradation_module.c
-rw-r--r-- 1 1001 1001   5536 Oct 19 16:02 ngx_http_empty_gif_module.c
-rw-r--r-- 1 1001 1001 113329 Oct 19 16:02 ngx_http_fastcgi_module.c
-rw-r--r-- 1 1001 1001   6426 Oct 19 16:02 ngx_http_flv_module.c
-rw-r--r-- 1 1001 1001  22371 Oct 19 16:02 ngx_http_geoip_module.c
-rw-r--r-- 1 1001 1001  44070 Oct 19 16:02 ngx_http_geo_module.c
-rw-r--r-- 1 1001 1001 142741 Oct 19 16:02 ngx_http_grpc_module.c
-rw-r--r-- 1 1001 1001  17038 Oct 19 16:02 ngx_http_gunzip_filter_module.c
-rw-r--r-- 1 1001 1001  29921 Oct 19 16:02 ngx_http_gzip_filter_module.c
-rw-r--r-- 1 1001 1001   8468 Oct 19 16:02 ngx_http_gzip_static_module.c
-rw-r--r-- 1 1001 1001  21700 Oct 19 16:02 ngx_http_headers_filter_module.c
-rw-r--r-- 1 1001 1001  42569 Oct 19 16:02 ngx_http_image_filter_module.c
-rw-r--r-- 1 1001 1001  15036 Oct 19 16:02 ngx_http_index_module.c
-rw-r--r-- 1 1001 1001  20585 Oct 19 16:02 ngx_http_limit_conn_module.c
-rw-r--r-- 1 1001 1001  28816 Oct 19 16:02 ngx_http_limit_req_module.c
-rw-r--r-- 1 1001 1001  49773 Oct 19 16:02 ngx_http_log_module.c
-rw-r--r-- 1 1001 1001  15012 Oct 19 16:02 ngx_http_map_module.c
-rw-r--r-- 1 1001 1001  21205 Oct 19 16:02 ngx_http_memcached_module.c
-rw-r--r-- 1 1001 1001   6794 Oct 19 16:02 ngx_http_mirror_module.c
-rw-r--r-- 1 1001 1001 118391 Oct 19 16:02 ngx_http_mp4_module.c
-rw-r--r-- 1 1001 1001   6976 Oct 19 16:02 ngx_http_not_modified_filter_module.c
-rw-r--r-- 1 1001 1001 142075 Oct 19 16:02 ngx_http_proxy_module.c
-rw-r--r-- 1 1001 1001   8973 Oct 19 16:02 ngx_http_random_index_module.c
-rw-r--r-- 1 1001 1001  26701 Oct 19 16:02 ngx_http_range_filter_module.c
-rw-r--r-- 1 1001 1001  15328 Oct 19 16:02 ngx_http_realip_module.c
-rw-r--r-- 1 1001 1001  17385 Oct 19 16:02 ngx_http_referer_module.c
-rw-r--r-- 1 1001 1001  28370 Oct 19 16:02 ngx_http_rewrite_module.c
-rw-r--r-- 1 1001 1001  61441 Oct 19 16:02 ngx_http_scgi_module.c
-rw-r--r-- 1 1001 1001   9205 Oct 19 16:02 ngx_http_secure_link_module.c
-rw-r--r-- 1 1001 1001  14029 Oct 19 16:02 ngx_http_slice_filter_module.c
-rw-r--r-- 1 1001 1001   6615 Oct 19 16:02 ngx_http_split_clients_module.c
-rw-r--r-- 1 1001 1001  79675 Oct 19 16:02 ngx_http_ssi_filter_module.c
-rw-r--r-- 1 1001 1001   2800 Oct 19 16:02 ngx_http_ssi_filter_module.h
-rw-r--r-- 1 1001 1001  39456 Oct 19 16:02 ngx_http_ssl_module.c
-rw-r--r-- 1 1001 1001   2105 Oct 19 16:02 ngx_http_ssl_module.h
-rw-r--r-- 1 1001 1001   8072 Oct 19 16:02 ngx_http_static_module.c
-rw-r--r-- 1 1001 1001   6094 Oct 19 16:02 ngx_http_stub_status_module.c
-rw-r--r-- 1 1001 1001  26018 Oct 19 16:02 ngx_http_sub_filter_module.c
-rw-r--r-- 1 1001 1001  10833 Oct 19 16:02 ngx_http_try_files_module.c
-rw-r--r-- 1 1001 1001  18728 Oct 19 16:02 ngx_http_upstream_hash_module.c
-rw-r--r-- 1 1001 1001   7555 Oct 19 16:02 ngx_http_upstream_ip_hash_module.c
-rw-r--r-- 1 1001 1001  14923 Oct 19 16:02 ngx_http_upstream_keepalive_module.c
-rw-r--r-- 1 1001 1001   8198 Oct 19 16:02 ngx_http_upstream_least_conn_module.c
-rw-r--r-- 1 1001 1001  12803 Oct 19 16:02 ngx_http_upstream_random_module.c
-rw-r--r-- 1 1001 1001   8644 Oct 19 16:02 ngx_http_upstream_zone_module.c
-rw-r--r-- 1 1001 1001  25004 Oct 19 16:02 ngx_http_userid_filter_module.c
-rw-r--r-- 1 1001 1001  75803 Oct 19 16:02 ngx_http_uwsgi_module.c
-rw-r--r-- 1 1001 1001  29999 Oct 19 16:02 ngx_http_xslt_filter_module.c
drwxr-xr-x 2 1001 1001    126 Mar 12 20:24 perl

但是当我尝试构建 nginx 包时,然后运行 nginx -V 来检查已安装的模块,似乎没有任何模块被加载:

[root@centos-7-2 nginx-1.22.1]# ./configure --prefix=/usr/local/nginx
checking for OS
 + Linux 3.10.0-1160.31.1.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-44) (GCC) 

........................
.............
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
    -o objs/ngx_modules.o \
    objs/ngx_modules.c
cc -o objs/nginx \
objs/src/core/nginx.o \
.....................
objs/src/http/modules/ngx_http_upstream_zone_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
    -e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
    -e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
    -e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
    < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/usr/local/nginx-1.22.1'
# make&make install
make -f objs/Makefile install
make[1]: Entering directory `/usr/local/nginx-1.22.1'
test -d '/usr/local/nginx' || mkdir -p '/usr/local/nginx'
..................
make[1]: Leaving directory `/usr/local/nginx-1.22.1'
[root@centos-7-2 nginx-1.22.1]# 
# ./nginx -V
nginx version: nginx/1.22.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
configure arguments: --prefix=/usr/local/nginx

真的不确定如何使用原始包含的 http 模块,我想使用的预期 http 模块是 ngx_http_log_module.c,根据 https://nginx.org/en/docs/http/ngx_http_session_log_module 页面上的官方说明.html,以下指令无法成功使用:

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            session_log one;
        }
.......

# ./nginx -t
nginx: [emerg] unknown directive "session_log" in /usr/local/nginx/conf/nginx.conf:47
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

顺便说一句,我也尝试过在./configure阶段使用--add-module的配置参数,但似乎不起作用。

提前感谢您的帮助。

.................................

nginx nginx-reverse-proxy
1个回答
0
投票

NGINX 会话日志

指令

session_log
来自http_session_log模块,在它的文档中提到了指令:

Syntax:     

session_log name | off;

Default:    off;

Context:    http, server, location

启用指定会话日志的使用。特别值关 取消从继承的 session_log 指令的效果 以前的配置级别。

还有更多指令,例如:

session_log_format name string ...;
session_log_zone path zone=name:size [format=format] 

NGINX 完整构建和/或动态模块

有“很多”方法可以使用自定义/“所有”模块构建 nginx,你应该通过研究它们是如何做到的而获得成功,但你应该已经能够“只启用”它

© www.soinside.com 2019 - 2024. All rights reserved.