# Squid 로깅 설정

### 1. Squid에서 PLURA 로깅 연동 설정 <a href="#id-1" id="id-1"></a>

* Forward 프록시로 Squid를 사용할 때, PLURA 로깅을 연동하는 방법입니다.&#x20;
* httpd와 유사한 방식으로 설정할 수 있습니다.

```
 logformat httpd %>a %[ui %[un [%tl] “%rm %ru HTTP/%rv” %>Hs %<st “%{Referer}>h” “%{User-Agent}>h” %Ss:%Sh
 access_log /var/log/squid/access.log httpd
```

### 2. PLURA 로깅을 JSON 형식으로 저장하는 방법 <a href="#id-2" id="id-2"></a>

* 다음과 같이 `squid.conf` 파일을 수정하여 JSON 형식으로 로깅 데이터를 저장할 수 있습니다.

```bash
vi /etc/squid/squid.conf
```

```
 forwarded_for on
 acl has-xff req_header X-Forwarded-For ^(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)|(\[([0-9a-f]+)?:([0-9a-f:]+)?:([0-9a-f]+|0-9\.]+)?\]))

 # add logging for PLURA
 logformat combinedjson {“Remote-addr”: “%>a”, “X-forwarded-for”: “%{X-Forwarded-For}>h”, “Request-date”: “%tl”, “Method”: “%rm”, “Request”: “%rm %rp HTTP/%rv”, “Host”: “%>rd”, “Uri”: “%ru”, “Resp-Content-Type”: “%mt”, “Refere”: “%{Referer}>h”, “User-Agent”: “%{User-Agent}>h”, “Status”: “%>Hs”, “Resp-Content-Length”: “%<st”, “ProxyStatus”: “%Ss:%Sh”}

 #access_log /var/log/squid/access.log combinedjson
 access_log stdio:/var/log/plura/weblog.log combinedjson !has-xff
 access_log stdio:/var/log/plura/weblog.log combinedjson has-xff
```

▶ Git source

> &#x20;<https://github.com/QubitSecurity/ModPlura/tree/main/squid>

### 3. Squid를 PLURA 웹 호스트로 인식시키기 <a href="#id-3" id="id-3"></a>

* 다음 명령어를 통해 Squid를 PLURA 시스템에 웹 호스트로 등록합니다.

```bash
echo “ModPlura-squid” > /etc/modplura
```

```bash
echo “0.0.1” >> /etc/modplura
```

```bash
touch /etc/.modplura
```

### 4. Squid Access 로그 파일에 권한 부여 <a href="#id-4" id="id-4"></a>

* 로그 파일에 권한을 부여하여 로그가 정상적으로 기록될 수 있도록 설정합니다.

```bash
touch /var/log/plura/weblog.log
```

```bash
chmod -R 766 /var/log/plura/weblog.log
```

```bash
chcon -t squid_log_t /var/log/plura/weblog.log
```

* [시스템 > 시스템 관리](https://docs.plura.io/ko/function/common/system/management)에서 리스트의 호스트를 확장하면 다음과 같이 확인됩니다.

<figure><img src="https://qubitsec.github.io/docs/images/Additianal/proxy/02.png" alt=""><figcaption></figcaption></figure>

### 참고 사이트 <a href="#id-5" id="id-5"></a>

> <http://www.squid-cache.org/Doc/config/logformat/>
>
> <https://bit.ly/36DjfZ3>
>
> <https://bit.ly/3hzt6Fw>
>
> <https://gist.github.com/kosho/82546a86140ad67c866e8197d730c53c>

<br>

### 참고사이트 XFF <a href="#id-6" id="id-6"></a>

> <https://gist.github.com/alvarow/fa409edc70aeb4cf89bbc83c1c78f392>
