模块分类
- 官方模块
- 第三方模块
所编译的模块
–with 后面主要是 所开启的模块1
2
3
4
5
6[root@instance-2 ~]# nginx -V
nginx version: nginx/1.18.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
–with-http_stub_status_module
Nginx 的客户端状态
示例
1 | root@R7000:/etc/nginx/conf.d# cat test.conf |
–with-http_random_index_module
目录中选择一个作为随机主页
1 | root@R7000:/etc/nginx/conf.d# cat test.conf |
–with-http_sub_module
HTTP 内容替换
1 | location / { |
连接请求限制
连接限制
limit_conn_zone key zone=name:size
limit_conn_zone number
请求限制
limit_req_zone zone=name:size rate=rate
limit_req_zone=name [burst=number][nodelay]
1 | limit_conn_zone $binary_remote_addr zone=conn_zone:1m; |
访问控制
基于 ip
http_access_module
局限性: 可能获取不到用户的真实 ip
x_forwarded_for=IP1,IP2…. 一般 IP1 为用户 IP ,但可能被篡改
使用 geo 模块 ,或者 通过 HTTP 自定义变量传递
1 | location ~ ^/admin.html { |
基于用户的信任登录
http_auth_basic_module
局限性: 用户信息依赖文件,效率低下
使用 LUA
利用 nginx-auth-ldap 模块