"Nginx"의 두 판 사이의 차이

wwiki
이동: 둘러보기, 검색
1번째 줄: 1번째 줄:
 +
== Admin Guide ==
 +
 +
=== Security Controls ===
 +
 +
==== Restricting Access with HTTP Basic Authentication ====
 +
 +
===== Creating a Password File =====
 +
<br />
 
== http core module ==
 
== http core module ==
  

2022년 2월 12일 (토) 06:49 판

Admin Guide

Security Controls

Restricting Access with HTTP Basic Authentication

Creating a Password File


http core module

location

Syntax:	location [ = | ~ | ~* | ^~ ] uri { ... }
location @name { ... }
Default:	
Context:	server, location

예제

location = / {
    [ configuration A ]
}

location / {
    [ configuration B ]
}

location /documents/ {
    [ configuration C ]
}

location ^~ /images/ {
    [ configuration D ]
}

location ~* \.(gif|jpg|jpeg)$ {
    [ configuration E ]
}

“/” 를 요청하면 설정A가 매칭될 것이다.

“/index.html” 을 요청하면 설정B가 매칭될 것이다.

“/documents/document.html”을 요청하면 설정C가 매칭될 것이다.

“/images/1.gif”를 요청하면 설정D가 매칭될 것이다.

“/documents/1.jpg”를 요청하면 설정E가 매칭될 것이다.

보안설정

#/etc/nginx/nginx.conf

서버 버전 숨기기 등

http{
    # 서버 버전 숨기기
    server_tokens off; 
    # 개발언어 숨기기
    fastcgi_hide_header X-Powered-By;
    proxy_hide_header X-Powered-By;
    # http 프로토콜에서 xml 데이터를 전송하기위해 사용되는데, 특별한 용도가 없다면 막아두는것이 좋다.
    fastcgi_hide_header X-Pingback;
    proxy_hide_header X-Pingback;
    # xml 관련된 W3c 표준이긴한데, 특별한 용도가 없다면 막아두는것이 좋다.
    fastcgi_hide_header Link;
    proxy_hide_header X-Link;
}

첫 페이지 제거

location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                #try_files $uri $uri/ =404;
                return 404;
        }

특정url제거

location /share2 {

                return 404;
        }

에러페이지 제거

error_page 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 495 496 497 500 501 502 503 504 505 506 507 /error.html;

location = /error.html {

                internal;
}

error.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >

</head>

<body>

<center>

<br><h1>ERROR</h1>

</center>

</body>

</html>

해외아이피 차단

nginx geo ip 모듈 설치 확인: --with-http_geoip_module=dynamic

$ /usr/sbin/nginx -V

geoip 데이터베이스 패키지 설치

$ sudo apt install geoip-database

설정파일에 국가 추가하기: /etc/nginx/nginx.conf

    #특정국가 IP 차단하기 
    geoip_country /usr/share/GeoIP/GeoIP.dat;
    map $geoip_country_code $allowed_country {
        default yes;
        RU no;
        CN no;
    }

server블록에 추가

if ($allowed_country = no) {
    return 444;
}

테스트: https://www.locabrowser.com/

에러

client intended to send too large body

server블록에 다음 추가

client_max_body_size 512M;

SSL routines:tls_process_client_hello:version too low

IE 6.0등 브라우저 버전이 낮은 경우에 발생한 보안에러이다.