1.安装nginx
#安装编译依赖包和工具
yum -y install epel-release wget python-pip gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel libxslt-devel gd-devel GeoIP GeoIP-devel GeoIP-data git
pip install pygeoip
pip install ipaddr
cd /usr/local/src/
#下载nginx文件并解压
wget http://nginx.org/download/nginx-1.21.4.tar.gz && tar xzvf nginx-1.21.4.tar.gz
RUN mkdir /var/cache/nginx/client_temp -p
#创建nginx用户
useradd -M -s /sbin/nologin nginx
#切换工作目录
WORKDIR /usr/local/src/nginx-1.21.4
#编译安装nginx
./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_degradation_module && make && make install
#下载成功地址库
mkdir /etc/nginx/geoip && cd /etc/nginx/geoip
wget https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-Country-CSV&license_key=YOUR_LICENSE_KEY&suffix=zip
git clone https://github.com/sherpya/geolite2legacy.git
cd geolite2legacy && ./geolite2legacy.py -i ../GeoLite2-Country-CSV_20211116.zip -f geoname2fips.csv -o
编辑配置nginx.conf文件
vim /etc/nginx/nginx.conf
在http模块中添加
geoip_country /etc/nginx/geoip/GeoIP.dat;
配置server配置文件
if ($geoip_country_code != "CN") {
return 500 $geoip_country_code.not,support;
}
上次更新时间 13 3 月, 2023 at 09:59 上午