当前位置: 首页 > news >正文

网站开发是什东莞网站建设选菲凡网络

网站开发是什,东莞网站建设选菲凡网络,网上租服务器价格表,东莞网站平台价格使用场景 过滤指定地区/国家的IP,一般是国外IP禁止请求。 使用geoip模块实现不同国家的请求被转发到不同国家的nginx服务器,也就是根据国家负载均衡。 前置知识 GeoIP是什么? 官网地址 https://www.maxmind.com/en/home包含IP地址的地理位…

使用场景

过滤指定地区/国家的IP,一般是国外IP禁止请求。
使用geoip模块实现不同国家的请求被转发到不同国家的nginx服务器,也就是根据国家负载均衡。

前置知识

GeoIP是什么?
官网地址

https://www.maxmind.com/en/home

包含IP地址的地理位置的数据库。

分为收费版本和免费版本
收费版本为GeoIP2,免费版本为GeoIPlite

nginx plus版本,也就是收费版的配置较为简单,geoip库已经被内置到yum仓库中。

nginx开源版本则没有。

实现

下载geoip模块
最新的release中作者说支持1.20版本,实测nginx1.24版本也支持

https://github.com/leev/ngx_http_geoip2_module

配置编译nginx的依赖。
我的做法是先配置nginx的官方源,
yum安装最新版stable的nginx,
nginx -V获取默认的编译参数,
然后再下载nginx对应版本的源码包进行编译替换nginx二进制文件即可。

下载geo模块到指定目录,解压,编译参数指定即可

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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_geoip_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 --add-dynamic-module=/opt/nginx/geo/ngx_http_geoip2_module-3.4 --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

注意参数--add-dynamic-module=/opt/nginx/geo/ngx_http_geoip2_module-3.4

之后执行make编译命令,编译之后nginx二进制文件会在源码包的objs目录中,验证是否编译成功

[root@localhost nginx-1.24.0]# cd objs/
[root@localhost nginx-1.24.0]#  ./nginx -V
nginx version: nginx/1.24.0
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/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_geoip_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 --add-dynamic-module=/opt/nginx/geo/ngx_http_geoip2_module-3.4 --with-cc-opt='-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

替换掉原来的nginx文件,nginx支持不停机升级,我这里由于没有服务在运行,就直接停机替换文件升级了。

# 找到nginx的执行路径
whereis nginx
cp 备份
cp ./objs/nginx 到原有执行路径

配置文件编写

load_module /opt/nginx/nginx-1.24.0/objs/ngx_http_geoip2_module.so;# 以下内容位于http模块中server_tokens off;charset utf-8;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"''"$geoip2_country_code" $geoip2_country_name_cn';  # 日志中显示访问国家,地区access_log  /var/log/nginx/access.log  main;sendfile            on;tcp_nopush          on;tcp_nodelay         on;real_ip_header X-Forwarded-For;map $http_x_forwarded_for $realip {~^(\d+\.\d+\.\d+\.\d+) $1;default $remote_addr;}geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {  # 加载模块$geoip2_country_code source=$realip country iso_code;$geoip2_country_name_en source=$realip country names en;$geoip2_country_name_cn source=$realip country names zh-CN;}

未完,有空再写。

http://www.yayakq.cn/news/880582/

相关文章:

  • 请人制作一个网站需要多少钱视频号的链接在哪
  • 凡科做网站行吗邯郸网络科技有限公司哪家好
  • 网站内部链接的策略制作图片怎么做
  • 网站开发静态怎样转成动态千家美家装体验馆
  • wordpress 旅游网站湖北省最新消息今天
  • 数学网站怎么做的艺术网站源码
  • 企业网站可信度建设php网站开发实训感想
  • 免费建网站讨论wordpress下单邮件通知的实现
  • 购物网站模版html设计一套网页要多少钱
  • 重养网站建设宿州市住房 建设 官方网站
  • 深圳网站营销公司简介专门做封面的网站
  • 购物网站的设计思路wordpress文章标题源码插件
  • 我的世界找建筑网站评论回复网站怎么做的
  • 做网站域名和空间费建立wordpress网站吗
  • 营销一型网站建设公司吉林网站建站系统平台
  • 国内做外贸的网站网站域名实名制
  • 网站建设投标书怎么制作下载手机导航地图
  • 龙江手机网站建设产品展示网站系统
  • 广东省建设工程协会网站做网站多少钱PageAdmin
  • 外贸建站服务阿里云服务器上如何做网站
  • 国外的设计网站手机怎么制作视频短片
  • 女性手机网站模板可商用图片素材网站
  • 泉州专业做网站开发my63777免费域名查询
  • 印记室内设计网站网页版游戏链接
  • 学校网站建设会议讲话稿机器人学做玩 网站
  • 网站模版网 下载视频制作报价表
  • 网站建设教程金旭亮视频格式转换网页版
  • 重庆做网站及公众号公司wordpress主题缺少样表
  • 网站开发好做还是平面好做建设网站的技术风险
  • 遵义市住房城乡建设局网站网站注册费