Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#76 Nginx 요청을 구분한다 #77

Merged
merged 1 commit into from
Aug 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions nginx/sites-available/default
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ server {
server_name www.logbat.info logbat.info api.logbat.info sdk.logbat.info view.logbat.info nginx.logbat.info;

return 301 https://$host$request_uri; # HTTP 요청을 HTTPS로 리디렉션
# managed by Certbot
}

server {
Expand Down Expand Up @@ -33,6 +32,9 @@ server {

include /etc/nginx/snippets/private-ip.conf;

access_log /var/log/nginx/api_access.log; # api.logbat.info 전용 액세스 로그 파일
error_log /var/log/nginx/api_error.log; # api.logbat.info 전용 에러 로그 파일

location /logs {
proxy_pass $logbat_server;
proxy_set_header Host $host;
Expand Down Expand Up @@ -124,12 +126,12 @@ server {
location /count {
content_by_lua_block {
-- access.log의 라인 수를 세어 successCount로 사용
local handle_access = io.popen("wc -l /var/log/nginx/access.log | cut -d' ' -f1")
local handle_access = io.popen("wc -l < /var/log/nginx/api_access.log")
local successCount = handle_access:read("*a")
handle_access:close()

-- error.log의 라인 수를 세어 errorCount로 사용
local handle_error = io.popen("wc -l /var/log/nginx/error.log | cut -d' ' -f1")
local handle_error = io.popen("wc -l < /var/log/nginx/api_error.log")
local errorCount = handle_error:read("*a")
handle_error:close()

Expand All @@ -142,8 +144,8 @@ server {
location /count/reset {
content_by_lua_block {
-- 로그 파일 지우기
os.execute("sudo truncate -s 0 /var/log/nginx/access.log")
os.execute("sudo truncate -s 0 /var/log/nginx/error.log")
os.execute("sudo truncate -s 0 /var/log/nginx/api_access.log")
os.execute("sudo truncate -s 0 /var/log/nginx/api_error.log")

-- 204 상태 코드 반환
ngx.status = ngx.HTTP_NO_CONTENT
Expand Down
Loading