nginx echo模块

http://wiki.nginx.org/HttpEchoModule

我这里在ubuntu下使用nginx,

查看nginx版本,nginx -V

nginx version: nginx/1.1.19

确保有nginx-echo模块

–add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo

接下来在ip.jpuyy.com中添加配置,返回客户端ip,同时在http头中也加返回客户端ip

server {
        listen       80;
        server_name  ip.jpuyy.com;

        location / {
            root /usr/share/nginx/jpuyy.com;
            index ip.html;
            add_header X-Client-IP $remote_addr;
            echo $remote_addr;
        }

}

获取自己的ip地址

➜  curl ip.jpuyy.com

183.195.128.xx

➜  curl -I ip.jpuyy.com

HTTP/1.1 200 OK

Server: nginx/1.1.19

Date: Sat, 23 Aug 2014 05:24:03 GMT

Content-Type: application/octet-stream

Connection: keep-alive

X-Client-IP: 183.195.128.xx

curl -I ip.jpuyy.com | grep X-Client |sed ‘s/ //’ | cut -d: -f2

发表评论

电子邮件地址不会被公开。 必填项已用*标注