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即可
相關文章
- SpringMVC配置攔截器SpringMVC
- 記一次nginx攔截爬蟲Nginx爬蟲
- 攔截器,攔截器棧總結
- cisco路由器上配置TCP攔截路由器TCP
- struts的常用配置以及自定義攔截器
- jpcap安裝與配置、資料包攔截PCA
- SpringMVC攔截器,設定不攔截的URLSpringMVC
- MyBatis攔截器MyBatis
- Mybatis 攔截器MyBatis
- 前端架構之vue+axios 前端實現登入攔截(路由攔截、http攔截)前端架構VueiOS路由HTTP
- TCP標誌位詳解及tcp攔截配置TCP
- vue中用axios攔截器攔截請求和響應VueiOS
- 根據IP獲取國家
- SpringBoot自定義攔截器實現IP白名單功能Spring Boot
- win10 microsoft edge網址被攔截如何取消攔截Win10ROS
- SpringBoot 2.X配置登入攔截器Spring Boot
- 配置filter攔截forward之類的內部轉發FilterForward
- axios攔截器iOS
- Mybatis Interceptor 攔截器MyBatis
- Xposed攔截抽象方法抽象
- WKCrashSDK - crash攔截工具
- axios 攔截器iOS
- spring攔截器Spring
- Java interceptor 攔截器Java
- IOS 手勢攔截iOS
- SpringMVC攔截器SpringMVC
- 寶塔皮膚nginx防火牆非瀏覽器攔截真的有用嗎?Nginx防火牆瀏覽器
- 根據IP獲取國家省市
- Flume內建攔截器與自定義攔截器(程式碼實戰)
- Java Filter過濾器(攔截路徑的配置+攔截方式的配置+生命週期+多個過濾器的先後執行順序)JavaFilter過濾器
- SpringMVC-攔截器SpringMVC
- 攔截過濾器模式過濾器模式
- gRPC(3):攔截器RPC
- 【SpringMVC】 4.3 攔截器SpringMVC
- 2.攔截WebView事件WebView事件
- 微信域名攔截檢測
- web api新增攔截器WebAPI
- spring boot 攔截器Spring Boot