我已经使用 gunciron 和 django 设置了 Nginx。一切似乎都运行良好,至少我相信是这样。但是,当我检查指定在 docker 中创建的 .gunicorn-logs 目录并指定下面的 myscipt.sh 时,它显示了 2 个文件:
access.log 包含对 gunciron 服务器的所有访问权限 &
error.log 应该为空,但却显示 1 kb 的文件。
Upon inspection, I get this inside --->
Gunicorn error.log file --->
[2024-12-05 04:36:15 +0000] [85] [INFO] Starting gunicorn 23.0.0
[2024-12-05 04:36:15 +0000] [85] [INFO] Listening at: http://0.0.0.0:8585 (85)
[2024-12-05 04:36:15 +0000] [85] [INFO] Using worker: gthread
[2024-12-05 04:36:15 +0000] [88] [INFO] Booting worker with pid: 88
[2024-12-05 04:36:15 +0000] [89] [INFO] Booting worker with pid: 89
[2024-12-05 04:36:15 +0000] [90] [INFO] Booting worker with pid: 90
[2024-12-05 04:36:15 +0000] [91] [INFO] Booting worker with pid: 91
Gunciron access.log file --->
49.xxx.xxx.xx - - [05/Dec/2024:10:06:26 +0530] "GET /admin/login/?next=/admin/ HTTP/1.1" 200 4158 "-" "PostmanRuntime/7.43.0"
127.0.0.1 - - [05/Dec/2024:10:06:35 +0530] "GET /static/admin/ HTTP/1.1" 302 0 "-" "PostmanRuntime/7.43.0"
127.0.0.1 - - [05/Dec/2024:10:06:36 +0530] "GET /admin/login/?next=/static/admin/ HTTP/1.1" 200 4172 "http://34.xxx.xxx.xx:75/static/admin/" "PostmanRuntime/7.43.0"
127.0.0.1 - - [05/Dec/2024:10:06:42 +0530] "GET /static/admin/ HTTP/1.1" 302 0 "-" "PostmanRuntime/7.43.0"
127.0.0.1 - - [05/Dec/2024:10:06:42 +0530] "GET /admin/login/?next=/static/admin/ HTTP/1.1" 200 4172 "http://34.xxx.xxx.xx:75/static/admin/" "PostmanRuntime/7.43.0"
nginx 日志文件只有 access.log 已填满,而 error.log 为空。
Nginx access.log file ---->
49.xxx.xxx.xx - - [05/Dec/2024:04:36:35 +0000] "GET /static/admin/ HTTP/1.1" 302 0 "-" "PostmanRuntime/7.43.0" "-"
49.xxx.xxx.xx - - [05/Dec/2024:04:36:36 +0000] "GET /admin/login/?next=/static/admin/ HTTP/1.1" 200 1522 "http://34.xxx.xxx.xx:75/static/admin/" "PostmanRuntime/7.43.0" "-"
49.xxx.xxx.xx - - [05/Dec/2024:04:36:42 +0000] "GET /static/admin/ HTTP/1.1" 302 0 "-" "PostmanRuntime/7.43.0" "-"
49.xxx.xxx.xx - - [05/Dec/2024:04:36:42 +0000] "GET /admin/login/?next=/static/admin/ HTTP/1.1" 200 1526 "http://34.xxx.xxx.xx:75/static/admin/" "PostmanRuntime/7.43.0" "-"
下面是我在 dockerFile 中定义 gunicorn 服务器相关行的方法。
RUN mkdir -p .gunicorn-logs
RUN touch /opt/.gunicorn-logs/error.log
RUN touch /opt/.gunicorn-logs/access.log
RUN chmod +x /opt/.gunicorn-logs/
cmd myscipt.sh
nginx 和 gunciron 均被调用的 myscript.sh --->
#!/bin/sh
nginx -g 'daemon off;' &
gunicorn mydjangoapi.wsgi:application --config=gunicorn_config_api-1.py
最后,根文件夹的 gunicorn_config_api-1.py 部分 --->
bind = "0.0.0.0:8585"
loglevel = "INFO"
workers = "4"
threads="10"
reload = True
errorlog = "/opt/.gunicorn-logs/error.log"
accesslog = "/opt/.gunicorn-logs/access.log"
当您设置时,
loglevel = "INFO"
您选择接收[INFO]
-severity 消息。在明确要求之后,您完全可以期待看到它们。