一聚教程网:一个值得你收藏的教程网站

热门教程

nginx中 echo模块使用例子

时间:2022-06-30 18:40:43 编辑:袖梨 来源:一聚教程网

我这里在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

热门栏目