[nginx]-nginx编译安装geop ip模块

nginx编译安装geop ip模块

首先下载nginx安装包

cd /tmp

wget http://nginx.org/download/nginx-1.15.8.tar.gz

解压安装包

tar zxvf nginx-1.15.8.tar.gz

安装依赖

yum -y install gcc gcc-c++ autoconf automake make

yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

yum -y install GeoIP GeoIP-devel GeoIP-data

 

cd nginx-1.15.8

编译安装

./configure --with-http_ssl_module  --with-http_stub_status_module --with-http_flv_module --with-http_gzip_static_module --with-http_realip_module --with-http_geoip_module

 

make && make install

 

修改/usr/local/nginx/conf/nginx.conf

user root;

pid /var/run/nginx.pid;

worker_processes 1;

worker_rlimit_nofile 100000;

events {

    worker_connections 2048;

    multi_accept on;

    use epoll;

}

 

http {

    geoip_country /usr/local/nginx/conf/GeoIP.dat;

    geoip_city /usr/local/nginx/conf/GeoLiteCity.dat;

    server_tokens off;

    sendfile on;

    tcp_nopush on;

    tcp_nodelay on;

log_format access_json '{ "@timestamp": "$time_iso8601", '

                         '"time": "$time_iso8601", '

                         '"remote_addr": "$remote_addr", '

                         '"remote_user": "$remote_user", '

                         '"body_bytes_sent": "$body_bytes_sent", '

                         '"request_time": "$request_time", '

                         '"status": "$status", '

                         '"host": "$host", '

                         '"request": "$request", '

                         '"request_method": "$request_method", '

                         '"uri": "$uri", '

                         '"http_referrer": "$http_referer", '

                         '"body_bytes_sent":"$body_bytes_sent", '

                         '"http_x_forwarded_for": "$http_x_forwarded_for", '

                         '"geoip_country_name":"$geoip_country_name", '

                         '"geoip_city": "$geoip_city", '

                         '"http_user_agent": "$http_user_agent" '

                    '}';

  access_log  /var/log/nginx/access.log access_json;

  error_log   /var/log/nginx/error.log;

    client_body_buffer_size      64k;

    client_max_body_size         100m;

    client_header_buffer_size    1k;

    large_client_header_buffers  4 4k;

    output_buffers               1 32k;

    keepalive_timeout 60;

    keepalive_requests 100000;

    client_header_timeout 15;

    client_body_timeout 60;

    send_timeout 25;

    reset_timedout_connection on;

    limit_conn_zone $binary_remote_addr zone=addr:5m;

    limit_conn addr 100;

    include /usr/local/nginx/conf/mime.types;

    default_type text/html;

    charset UTF-8;

    gzip on;

    gzip_disable "MSIE [1-6]\.";

    gzip_proxied any;

    gzip_vary off;

    gzip_min_length 1000;

    gzip_comp_level 6;

    open_file_cache max=100000 inactive=20s;

    open_file_cache_valid 30s;

    open_file_cache_min_uses 2;

    open_file_cache_errors off;

server {

    listen       80;

    server_name  localhost;

 

location /nginx_status {

    stub_status on;

}

    location /myip {

        default_type text/plain;

        return 200 "$remote_addr $geoip_country_name $geoip_city  $geoip_latitude $geoip_longitude";

    }

location ~*\.(htm|eot|ttf|woff|html|js|css|less|json|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|docx|ppt|pdf|xls|xlsx|mp3|mp4|wma|apk|zip|rar|map)$ {

    root   /ftp/www/;

    index  index.html index.htm;

}

 

}  

   

·$geoip_country_code - 两个字母的国家代码,如:"RU", "US"。
·$geoip_country_code3 - 三个字母的国家代码,如:"RUS", "USA"。
·$geoip_country_name - 国家的完整名称,如:"Russian Federation", "United States"(如果可用)。
·$geoip_region - 地区的名称(类似于省,地区,州,行政区,联邦土地等),如:"Moscow City", "DC"(如果可用)。
·$geoip_city - 城市名称,如"Moscow", "Washington"(如果可用)。
·$geoip_postal_code - 邮政编码(如果可用)。
·$geoip_city_continent_code(如果可用)。
·$geoip_latitude - 所在维度(如果可用)。
·$geoip_longitude - 所在经度(如果可用)。

配置中  需要导入geo ip数据库  官网的下载似乎有问题。https://download.csdn.net/download/xujiamin0022016/10912529

修改之后/usr/local/nginx/sbin/nginx -t测试一下配置

没有报错的话 启动nginx

/usr/local/nginx/sbin/nginx

然后访问ip:/myip测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爷来辣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值