nginx配置攔截指定國家IP
wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
[root@localhost opt]# tar zxvf GeoIP.tar.gz
[root@localhost opt]# cd GeoIP-1.4.8
[root@localhost opt]# ./configure
[root@localhost opt]# make && make install
[root@localhost opt]# gunzip GeoIP.dat.gz
[root@localhost opt]# gunzip GeoLiteCity.dat.gz
[root@localhost opt]# mv GeoIP.dat /opt/nginx/geoip/
[root@localhost opt]# mv GeoLiteCity.dat /opt/nginx/geoip/
[root@localhost opt]# cat /opt/nginx/conf/nginx.conf
user www;
worker_processes 3;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /opt/nginx/conf/mime.types;
default_type application/octet-stream;
include /opt/nginx/sites-enabled/*;
geoip_country /opt/nginx/geoip/GeoIP.dat;
geoip_city /opt/nginx/geoip/GeoLiteCity.dat;
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 /var/log/nginx/access.log main;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
sendfile on;
#tcp_nopush on;
keepalive_timeout 300;
charset utf-8;
gzip on;
server_tokens off;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;
include /opt/nginx/conf.d/*.conf;
}
[root@localhost opt]# cat /opt/nginx/conf.d/www.cookie.com.conf
server {
listen 443;
server_name www.cookie.com;
if ($geoip_country_code = HK) {
return 404;
}
……
……
……
}
重啟nginx即可
相關文章
- Spring MVC 中的攔截器的使用“攔截器基本配置” 和 “攔截器高階配置”SpringMVC
- 記一次nginx攔截爬蟲Nginx爬蟲
- SpringBoot自定義攔截器實現IP白名單功能Spring Boot
- SpringBoot 2.X配置登入攔截器Spring Boot
- struts的常用配置以及自定義攔截器
- Proxy 攔截
- SpringMVC攔截器,設定不攔截的URLSpringMVC
- 前端架構之vue+axios 前端實現登入攔截(路由攔截、http攔截)前端架構VueiOS路由HTTP
- TCP標誌位詳解及tcp攔截配置TCP
- 導彈攔截
- sql攔截器SQL
- SpringMVC攔截器SpringMVC
- Mybatis 攔截器MyBatis
- axios 攔截器iOS
- spring攔截器Spring
- axios攔截器iOS
- MyBatis攔截器MyBatis
- win10 microsoft edge網址被攔截如何取消攔截Win10ROS
- SpringMVC-攔截器SpringMVC
- gRPC(3):攔截器RPC
- 【SpringMVC】 4.3 攔截器SpringMVC
- Xposed攔截抽象方法抽象
- Mybatis Interceptor 攔截器MyBatis
- WKCrashSDK - crash攔截工具
- spring boot 攔截器Spring Boot
- SpringBoot攔截器中獲取註解、攔截器中注入ServiceSpring Boot
- Spring Boot 第六彈,攔截器如何配置,看這兒~Spring Boot
- Asp.Netcore使用Filter來實現介面的全域性異常攔截,以及前置攔截和後置攔截ASP.NETNetCoreFilter
- Java Filter過濾器(攔截路徑的配置+攔截方式的配置+生命週期+多個過濾器的先後執行順序)JavaFilter過濾器
- 寶塔皮膚nginx防火牆非瀏覽器攔截真的有用嗎?Nginx防火牆瀏覽器
- Flume內建攔截器與自定義攔截器(程式碼實戰)
- mybatis註冊攔截器MyBatis
- SpringMVC中的攔截器SpringMVC
- grpc中的攔截器RPC
- HandlerInterceptor - 自定義攔截器
- 攔截過濾器模式過濾器模式
- 2.攔截WebView事件WebView事件
- Spring Boot新增攔截器Spring Boot
- SpringBoot 手寫攔截器Spring Boot