nginx에서 특정 IP에서만 xmlrpc.php 파일에 접근하도록 설정
워드프레스(WordPress)의 xmlrpc.php 파일을 이용한 공격에 대비하기 위해 nginx 에서 아래와 같이 설정한다.
location = /xmlrpc.php {
    deny all;
    access_log off;
    log_not_found off;
}그러나 위와 같이 설정했을 때 xmlrpc를 이용해 포스트를 등록하는 등의 작업을 할 수 없기 때문에 특정 아이피(IP)에서는 접근을 허용해야 하는 경우가 생긴다. 이 때는 보통 아래와 같이 설정을 한다.
location = /xmlrpc.php {
    allow 192.168.0.75;
    deny all;
    access_log off;
    log_not_found off;
}위와 같이 접근 허용 IP를 추가했을 때 쉘에서 curl -d -O https://chicpro.dev/xmlrpc.php 를 실행하면 405 (Not Allowed) 오류가 발생한다. PHP 파일에 대한 처리를 FPM에 넘겨주지 못하기 때문이다. 그래서 특정 IP에서 접근을 허용하고 PHP 파일에 대한 처리도 하기 위해서는 아래와 같이 설정해야 한다.
location = /xmlrpc.php {
    allow 192.168.0.75;
    deny all;
    access_log off;
    log_not_found off;
    include        fastcgi_params;
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_pass   127.0.0.1:9000;
    include mime.types;
}설정 변경 후 위의 curl 명령을 실행하면 허용된 IP에서는 아래와 같은 응답이 표시된다.
<?xml version="1.0" encoding="UTF-8"?>
<methodResponse>
  <fault>
    <value>
      <struct>
        <member>
          <name>faultCode</name>
          <value><int>-32700</int></value>
        </member>
        <member>
          <name>faultString</name>
          <value><string>parse error. not well formed</string></value>
        </member>
      </struct>
    </value>
  </fault>
</methodResponse>허용되지 않은 IP에서는 403 오류가 발생한다.
