반응형
NGINX 및 PHP-FPM Access Log 포맷 설정
nginx access log format 설정
vim /etc/nginx/nginx.conf
http {
...
log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$remote_addr"'
' REQ_TIME: $request_time s - CONNECT_TIME: $upstream_connect_time s - PHP-FPM_STATUS: $upstream_status';
access_log /var/log/nginx/access.log main;
...
}
설정 테스트 및 재시작
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
systemctl reload nginx
NGINX Access Log 변수 정리
변수 | 설명 |
$remote_addr | 클라이언트 IP 주소 |
$http_x_forwarded_for | 프록시를 통한 원래 클라이언트 IP |
$request | 요청 라인: GET /index.php HTTP/1.1 |
$status | 응답 상태 코드 (e.g. 200, 404, 500) |
$body_bytes_sent | 전송된 응답 바이트 수 |
$http_referer | 이전 페이지 URL |
$http_user_agent | 클라이언트의 User Agent |
$request_time | 전체 요청 처리 시간 (초) |
$upstream_connect_time | PHP-FPM과의 연결 시간 |
$upstream_status | PHP-FPM에서 반환한 상태 코드 |
http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
http://nginx.org/en/docs/http/ngx_http_upstream_module.html
728x90
php-fpm access log format 설정
vim /etc/php-fpm.d/www.conf
...
access.log = /var/log/php-fpm/www-access.log
access.format = "[%t] %m %{REQUEST_SCHEME}e://%{HTTP_HOST}e%{REQUEST_URI}e %f pid:%p took:%ds mem:%{mega}Mmb cpu:%C%% status:%s {%{REMOTE_ADDR}e|%{HTTP_USER_AGENT}e}"
...
설정 테스트 및 재시작
php-fpm -t
[15-Oct-2020 14:19:25] NOTICE: configuration file /etc/php-fpm.conf test is successful
systemctl reload php-fpm
PHP-FPM 로그 포맷
포맷 코드 | 설명 |
%t | 요청 수신 시간 (e.g. 28/Jul/2025:20:45:10 +0900) |
%m | HTTP 메서드 (GET, POST 등) |
%{...}e | $_ENV 또는 $_SERVER의 값 (ex. %{REQUEST_URI}e) |
%f | 실행된 PHP 파일 경로 |
%p | PHP-FPM 자식 프로세스 PID |
%d | 요청 처리 시간 (초) |
%M | 사용한 메모리 (MB 등 단위 선택 가능) |
%C | 요청 처리에 사용된 CPU 비율 |
%s | 응답 상태 코드 |
%R | 클라이언트 IP 주소 |
% | 클라이언트의 User Agent |
참고URL
- PHP Documentation : PHP Manual > Installation and Configuration > FastCGI Process Manager (FPM)
728x90
반응형
'리눅스' 카테고리의 다른 글
취약점을 방지하기 위한 보안 HTTP 헤더를 설정하기 (0) | 2020.10.21 |
---|---|
[리눅스] NGING에서 PHP-FPM 상태를 활성화하고 모니터링하는 방법 (0) | 2020.10.15 |
리눅스에서 tcping을 설치하고 사용하는 방법 (0) | 2020.10.14 |
openssl 인증서 만료일 조회 (0) | 2020.10.14 |
리눅스 ccze 명령어 (0) | 2020.10.13 |