Почему я не могу увидеть журнал NGINX, когда мое приложение развернуто в службах приложений Azure, но оно отлично работает локально?
У меня есть Dockerized Django-приложение, которое я оркестрирую с помощью Supervisor, что не оптимально, но необходимо при размещении на сервисах приложений Azure, поскольку их поддержка мульти-приложений с docker-compose все еще находится в режиме предварительного просмотра (ака. бета).
В соответствии с лучшими практиками я настроил каждое приложение в supervisord на передачу журналов в STDOUT. Все работает нормально, когда я создаю образ Docker локально, запускаю его и проверяю журналы docker. Однако, когда я развернул его в сервисах приложений Azure и проверил журналы, мое веб-приложение (Gunicorn) ведет журнал, как и ожидалось, однако журналы NGINX не появляются вообще.
Я пробовал различные конфигурации в своем Dockerfile для связывания файлов журналов, генерируемых NGINX (например, связывание с /dev/stdout и /dev/fd/1), а также заходил в конфигурацию nginx.conf и пытался выходить непосредственно на /dev/stdout. Но что бы я ни делал, локально все работает нормально, но на Azure в журналах не видно никаких NGINX-логов. Я вставил соответствующие файлы конфигурации, где вы можете увидеть закомментированные строки с опциями, которые я пробовал. Надеюсь, кто-нибудь поможет мне разобраться в этом вопросе.
Dockerfile
supervisord_main.conf
[supervisord]
logfile=/var/logs/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10 ; # of main logfile backups; 0 means none, default 10
loglevel=info ; log level; default info; others: debug,warn,trace
pidfile=/var/logs/supervisord.pid
nodaemon=true ; Run interactivelly instead of deamonizing
# user=www-data
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[inet_http_server]
port = 127.0.0.1:9001
[supervisorctl]
serverurl = http://127.0.0.1:9001
#serverurl=unix:///var/run/supervisor.sock
[program:nginx]
#command=/usr/local/bin/prefix-log /usr/sbin/nginx -g "daemon off;"
command=/usr/sbin/nginx -g "daemon off;"
directory=./projectile/
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile = /dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile = /dev/fd/2
stderr_logfile_maxbytes=0
[program:ssh]
command=/usr/local/bin/prefix-log /usr/sbin/sshd -D
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile = /dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile = /dev/fd/2
stderr_logfile_maxbytes=0
[program:web]
user=www-data
command=/usr/local/bin/prefix-log gunicorn --bind 0.0.0.0:8000 projectile.wsgi:application # Run each app trough a SH script to prepend logs with the application name
#command=gunicorn --workers=%(ENV_WORKER_COUNT)s --bind 0.0.0.0:8000 myapp_project.wsgi:application
directory=./projectile/
autostart=true
autorestart=true
stdout_events_enabled=true
stderr_events_enabled=true
stdout_logfile = /dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile = /dev/fd/2
stderr_logfile_maxbytes=0
nginx.conf
user nginx;
worker_processes 2; # Set to number of CPU cores, 2 cores under Azure plan P1v3
error_log /var/log/nginx/error.log warn;
#error_log /dev/stdout warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
#access_log /dev/stdout main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
staging.conf
server {
listen 80 default_server;
error_log /dev/stdout info;
access_log /dev/stdout;
client_max_body_size 100M;
location /static {
root /var/app/ui/build;
}
location /site-static {
root /var;
}
location /media {
root /var;
}
location / {
root /var/app/ui/build; # try react build directory first, if file doesn't exist, route requests to django app
try_files $uri $uri/index.html $uri.html @app;
}
location @app {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https"; # assumes https already terminated by the load balancer in front of us
proxy_pass http://127.0.0.1:8000;
proxy_read_timeout 300;
proxy_buffering off;
}
}
Решено. Проблема заключалась в том, что в службе Azure App был установлен параметр конфигурации WEBSITES_PORT=8000, который заставлял приложение обращаться непосредственно к gunicorn и обходить NGINX, не создавая никаких журналов. Простое удаление этого параметра устранило проблему.