Using the FastCGI module allowed me to pass on server variables directly onto my PHP application through the use of param. What I'm hoping to do next is record one of these params onto my NGINX access logs.
I've tried directly assigning this to the log format by the param's name, but it seems to result as a blank value. Later I've tried passing this param into an NGINX variable but no luck there as well.
In the following config, I've defined my own NGINX variable $logparam to store the value declared on my own custom FastCGI param LOG_PARAM, which does not seem to work that way.
If there's any possible solution to handle this, it would be very much appreciated.
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Adding nginx variable to access log format
log_format docker '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$logparam"';
include conf.d/*.conf;
map $http_upgrade $connection_upgrade {
default "upgrade";
}
server {
listen 80 default_server;
access_log /var/log/nginx/access.log docker;
# Declared variable to store fastcgi param
set $logparam "";
client_header_timeout 60;
client_body_timeout 60;
keepalive_timeout 60;
gzip off;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.php?_url=$uri&$args;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index /index.php;
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
include /etc/nginx/fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# Declared new param with custom value and passing onto nginx variable
fastcgi_param LOG_PARAM "testing";
set $logparam LOG_PARAM;
}
location ~ /\.ht {
deny all;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
}
}
}