Search code examples
nginxcentosunicorn

nginx: [emerg] invalid parameter "$remote_addr - $remote_user [$time_local] $request " in /etc/nginx/nginx.conf:24


Out error I tried start nginx in the following environment, did not go well.

#env
CentOS v6.5
nginx v1.6.1
unicorn v4.8.3

#error message
nginx: [emerg] invalid parameter "$remote_addr - $remote_user [$time_local] $request " in /etc/nginx/nginx.conf:24
nginx: configuration file /etc/nginx/nginx.conf test failed

#nginx.conf
http {

omit code

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent"';

access_log  /var/log/nginx/access.log  main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent"';

omit code...
}

added code in nginx.conf


Solution

  • You must set up log_format before access_log, not with one directive.

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent"';
    
    access_log /var/log/nginx/access.log main;
    

    nginx docs for log settings