NGINX geoip模块

文章介绍了如何在Nginx中使用geoip模块根据访问者来源IP的国家代码,将用户重定向到对应的中文、英文或德文官网。涉及SSL配置、目录重写规则以及GZIP压缩设置。
摘要由CSDN通过智能技术生成

根据来源IP跳转具体官网

编译安装Nginx 采用geoip模块

#user  nobody;
worker_processes  1;
 
events {
    worker_connections  1024;
}
 
 
http {
    include       mime.types;
    default_type  application/octet-stream;
 
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
    access_log  logs/access.log  main;
 
    sendfile        on;
    keepalive_timeout  65;
 
    #gzip  on;
    geoip_country  /server/tools/nginx-1.20.1/geoip/GeoIP.dat;
    geoip_city  /server/tools/nginx-1.20.1/geoip/GeoLiteCity.dat;
##############################################################测试 #################################################################
 
    server {
        listen       81;
        server_name  localhost;
        root  /server/tools/nginx-1.20.1/html;
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
        location / {
          if ($geoip_country_code = CN) {
              root /server/tools/nginx-1.20.1/html;
          }
          if  ($geoip_country_code != CN) {
              root /server/tools/nginx-1.20.1/html/test;
          }
 
     }  
 
}
 
 
##############################################################英文 官网#################################################################
server {
        listen 443 ssl;
        server_name www..com en.ong.com;
        root /ftpshare;
        index index.php index.html;
        ssl_certificate /server/tools/nginx-1.20.1/ssl/6543710__.com.pem;
        ssl_certificate_key /server/tools/nginx-1.20.1/ssl/6543710__.com.key;
        ssl_session_timeout  5m;    #缓存有效期
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;    #加密算法
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    #安全链接可选的加密协议
        ssl_prefer_server_ciphers on;   #使用服务器端的首选算法
 
location / {
         root /ftpshare;
         if (!-e $request_filename){
         rewrite ^(.*)$ /index.php?s=$1 last;
         break;
       }
 
         if ($geoip_country_code = CN) {
              rewrite ^/(.*) https://www.;
          }
   
}
 
 
location ~*  .*\.(jpg|gif|png)$ {
        root /ftpshare;
        gzip on;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png;
                 
        }
 
location ~ .*\.(jpg||jpeg|gif|png)$ {
    valid_referers none blocked test.zkong.com;
    if ($invalid_referer) {
        return 403;
    }
}
 
location ~ \.php$ {
            root /ftpshare;
            index index.php index.html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /ftpshare$fastcgi_script_name;
            include        fastcgi_params;
 
        }
}
 
server {
    listen       80;
    server_name  www..com.com;
    return 301 https://$server_name$request_uri;
}
 
 
##############################################################德文 官网#################################################################
 
 
server {
        listen 443 ssl;
        server_name de..com;
        root /usr/share/nginx/html;
        index index.php index.html;
        ssl_certificate /server/tools/nginx-1.20.1/ssl/6543710__.pem;
        ssl_certificate_key /server/tools/nginx-1.20.1/ssl/.com.key;
        ssl_session_timeout  5m;    #缓存有效期
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;    #加密算法
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;    #安全链接可选的加密协议
        ssl_prefer_server_ciphers on;   #使用服务器端的首选算法
 
 
 
 
location / {
         root /usr/share/nginx/html;
         if (!-e $request_filename){
         rewrite ^(.*)$ /index.php?s=$1 last;
         break;
           }
 
 
         if ($geoip_country_code = CN) {
              rewrite ^/(.*) https://www..cn;
          }
 
       }
 
 
   
location ~*  .*\.(jpg|gif|png)$ {
        root /usr/share/nginx/html;
        gzip on;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types text/plain application/json application/x-javascript application/css application/xml application/xml+rss text/javascript application/x-httpd-php image/jpeg image/gif image/png;
                 
        }
 
location ~ .*\.(jpg||jpeg|gif|png)$ {
        valid_referers none blocked test..com;
        if ($invalid_referer) {
        return 403;
           }
        }
 
        location ~ \.php$ {
            root /usr/share/nginx/html;
            index index.php index.html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
}
 
} #http区块

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值