我正在使用 Docker 創建一個基于 Django 的網站。我在管理 Gunicorn 的日志檔案時遇到了問題。使用下面的腳本,站點運行沒有問題:
#!/usr/bin/env bash
cd personal_website
exec gunicorn personal_website.wsgi:application \
--name personal_website \
--bind 0.0.0.0:"${PROJECT_PORT}" \
--workers 3 \
"$@"
這是我在終端上看到的:
dev_website | [2022-01-21 16:36:17 0000] [1] [INFO] Starting gunicorn 20.1.0
dev_website | [2022-01-21 16:36:17 0000] [1] [DEBUG] Arbiter booted
dev_website | [2022-01-21 16:36:17 0000] [1] [INFO] Listening at: http://0.0.0.0:8301 (1)
dev_website | [2022-01-21 16:36:17 0000] [1] [INFO] Using worker: sync
dev_website | [2022-01-21 16:36:17 0000] [11] [INFO] Booting worker with pid: 11
dev_website | [2022-01-21 16:36:17 0000] [12] [INFO] Booting worker with pid: 12
dev_website | [2022-01-21 16:36:17 0000] [13] [INFO] Booting worker with pid: 13
dev_website | [2022-01-21 16:36:17 0000] [1] [DEBUG] 3 workers
但是當我添加日志檔案時:
#!/usr/bin/env bash
# Prepare log files and start outputting logs to stdout
touch ./logs/gunicorn.log
touch ./logs/gunicorn-access.log
cd personal_website
exec gunicorn personal_website.wsgi:application \
--name personal_website \
--bind 0.0.0.0:"${PROJECT_PORT}" \
--workers 3 \
--log-level=debug \
--error-logfile=./logs/gunicorn.log \
--access-logfile=./logs/gunicorn-access.log \
"$@"
我看到下面的錯誤:
dev_website | Error: Error: './logs/gunicorn.log' isn't writable [FileNotFoundError(2, 'No such file or directory')]
并且網站無法運行。錯誤在哪里?我可以在專案卷中看到這兩個檔案。
uj5u.com熱心網友回復:
在您的 bash 腳本中,您首先觸摸(創建)日志檔案,然后更改作業目錄。當您啟動 Web 服務器時,這些檔案不是相對于當前作業目錄定位的。
換句話說,首先運行您的cd命令,然后再運行 2xtouch命令。
uj5u.com熱心網友回復:
問題是我正在將日志檔案搜索到錯誤的檔案夾中。
#!/usr/bin/env bash
# Prepare log files and start outputting logs to stdout
touch ./logs/gunicorn.log
touch ./logs/gunicorn-access.log
cd personal_website
exec gunicorn personal_website.wsgi:application \
--name personal_website \
--bind 0.0.0.0:"${PROJECT_PORT}" \
--workers 3 \
--log-level=debug \
--error-logfile=../logs/gunicorn.log \
--access-logfile=../logs/gunicorn-access.log \
"$@"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/420391.html
標籤:
