nginx使用ip反解域名

Posted by 刘勇(lyonger) on 2019-11-30

nginx使用ip反解域名

  1. 下载nginx源码,可以按照自己想要的版本来下载,这里以1.10来举例

  2. 下载rdns的源码

    1
    git clone https://github.com/flant/nginx-http-rdns.git
  3. 编译,安装nginx,配置参考如下,会有一些依赖包问题,根据编译提示安装依赖包,最重要的是最后的add-module=指定rdns的源码目录

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    cd nginx-1.10.1 && \
    ./configure \
    --prefix=/etc/nginx \
    --sbin-path=/usr/sbin/nginx \
    --modules-path=/usr/lib/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 \
    --with-http_geoip_module=dynamic \
    --with-http_image_filter_module=dynamic \
    --with-http_xslt_module=dynamic \
    --with-http_realip_module \
    --with-file-aio \
    --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_secure_link_module \
    --with-http_slice_module \
    --with-http_sub_module \
    --with-http_v2_module \
    --with-mail \
    --with-stream \
    --with-http_stub_status_module \
    --user=nginx \
    --group=nginx \
    --with-threads \
    --add-module=../nginx-http-rdns-master && \
    make && make install
  4. 配置nginx,配置可参考rdns的文档,如果是有location @的形式,需要在那里关掉rdns off;具体看rdns的文档

    1
    2
    3
    server {
    listen 0.0.0.0:1080;
    server_name localhost
     server_tokens off;
     resolver 42.186.69.116;
     rdns on;
     rdns_allow \.i\.nease\.net;
     rdns_deny .*;
     location / {
         include uwsgi_params;
         uwsgi_pass unix:/tmp/uwsgi.sock;
     }
    

    }

    1
    5. 如果你需要域名rdns反解和白名单共存形式,可以参考下面配置

    server {
    listen 0.0.0.0:1080;
    server_name localhost

    server_tokens off;
    satisfy any;
    resolver 42.186.69.116;
    rdns on;
    rdns_allow \.lyonger\.cn;
    rdns_deny .*;
    include /etc/nginx/conf.d/whitelist/*.list;
    deny all;
    location / {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/uwsgi.sock;
    }
}


推荐阅读



支付宝打赏 微信打赏

赞赏一下