15. Nginx Geo

5283 단어 nginxgeoip
새로운 방법
  • nginx 모듈 geoip 2 설치: https://github.com/leev/ngx_h...
  • IP 식별 데이터 원본 다운로드: https://www.maxmind.com/en/ac... 사이트 계 정 을 등록 해 야 다운로드 할 수 있 습 니 다. 다운로드 한 데이터베이스 선택 GeoLite2 CityGeoLite2 Country 하면 됩 니 다
  • nginx 설정 은 다음 과 같 습 니 다. source 옵션 은 $remote_addr 사용자 IP 를 분석 하고 다른 변수
  • 로 수정 할 수 있 습 니 다.
    http {
        ...
         geoip2 /etc/nginx/vendor/GeoLite2-Country.mmdb {
            auto_reload 5m;
            $geoip2_metadata_country_build metadata build_epoch;
            $geoip2_data_country_code default=US source=$remote_addr country iso_code;
            $geoip2_data_country_name country names en;
        }
    
        geoip2 /etc/nginx/vendor/GeoLite2-City.mmdb {
            $geoip2_data_city_name default=London city names en;
        }
    
        fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
        fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
        fastcgi_param CITY_NAME    $geoip2_data_city_name;
        ....
        
        server {
            listen 8081;
            server_name www.siguoya.name;
            location / {
                if ($geoip2_data_country_code != 'CN'){
                    return 403;
                }
                default_type text/plain;
                return 200 "$remote_addr $geoip2_data_country_code $geoip2_data_country_name $geoip2_data_city_name";
           }
       }
    }

    방문: http://www.siguoya.name:8081/
    113.111.3.206 CN China Guangzhou

    낡은 방법
    maxmind 에서 dat 형식의 데이터 다운로드 및 유 지 를 제공 하지 않 기 때문에 다음 방법 은 폐기 되 었 습 니 다.
    IP 데이터베이스 다운로드 주소: 국가 데이터베이스: http://geolite.maxmind.com/do... 도시 데이터베이스: http://geolite.maxmind.com/do...
    http {
      geoip_country /path/to/GeoIP.dat;
      geoip_city /path/to/GeoLiteCity.dat;
      server{
        listen 3592;
        location / {
          default_type text/plain;
          if ($geoip_country_code != 'CN'){
            return 403;
          }
          return 200 "$remote_addr $geoip_city_country_name $geoip_country_code $geoip_city";
        }
      }
    }
    

    방문: http://www.siguoya.name:3592/
    119.32.216.122 China CN Guangzhou

    특정한 제목 으로 읽다.
  • 1. Nginx 의 장점
  • 2. Nginx 의 설치 와 켜 기 자동 켜 기
  • 3. Nginx 디 렉 터 리 와 설정 문법
  • 4. Nginx 모듈
  • 5. Nginx 정적 자원 처리
  • 6. Nginx 브 라 우 저 캐 시 원리
  • 7. Nginx 자원 의 크로스 도 메 인 접근
  • 8. Nginx 자원 의 도 난 방지 체인
  • 9. Nginx 에이전트
  • 10. Nginx 부하 균형
  • 11. Nginx 캐 시
  • 12. Nginx 동정 분리
  • 13. Nginx Rewrite
  • 14. Nginx Secure Link
  • 15. Nginx Geo
  • 16. Nginx HTTPS 서비스
  • 17. Nginx 와 Lua 개발
  • 18. Nginx 와 Lua 그 레이스 케 일 발표
  • 19. Nginx 에서 흔히 볼 수 있 는 오류
  • 20. Nginx 성능 최적화
  • 21. Nginx 안전 관리
  • 좋은 웹페이지 즐겨찾기