本帖最后由 Pigod 于 2018-1-24 14:59 编辑
服务器上经常又一些外国ip乱扫,因为我运营的网站是纯中文站,完全就是给国人自己看的,干脆就屏蔽掉外国ip。nginx配合geoip模块效率还是很高的。所以就想给nginx加个geoip模块。看了下才发现宝塔安装软件不管是极速模式还是编译模式,参数都是固定的。
自己编译了个nginx,只添加了geoip模块,其他参数都跟宝塔官方的一样
具体参数如下:
# /www/server/nginx/sbin/nginx -V
nginx version: nginx/1.12.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2m 2 Nov 2017
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-http_geoip_module --with-ld-opt=-Wl,-E
使用说明:1、直接替换nginx文件就可以(记得备份)
2、下载 http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
3、解压放到你想放的位置去
4、nginx配置文件添加 geoip_country /www/server/panel/vhost/nginx/GeoIP.dat(改成你的GeoIP.dat文件的位置);
5、网站配置文件或者伪静态配置里添加:
#屏蔽非大陆ip访问
if ($geoip_country_code != CN ) {
return 403;
}
#屏蔽非大陆ip访问
这个只是根据我个人的需求的配置,所有非中国大陆ip都直接屏蔽掉,如果有别的需求自行更改即可
2018-1-24 14:55 上传
点击文件名下载附件
13.32 MB, 下载次数: 779
添加geoip模块的nginx