Currently when I compile nginx (in directory /home/parth/nginx), it embeds the prefix supplied to configure script in the nginx binary. Now when I move that folder around (let's say to /tmp), it breaks with following error message. Is there a way to configure logs file directories?

./nginx -p /tmp/ -c /tmp/conf/nginx.conf

nginx: [alert] could not open error log file: open() "/home/parth/nginx/var/logs/error.log" failed (2: No such file or directory) 2012/08/27 02:22:26 [emerg] 23782#0: unknown log format "main" in /tmp/conf/nginx.conf:25

== nginx.conf file ==

#user  nobody;
worker_processes  1;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
    worker_connections  1024;

http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        access_log  logs/host.access.log  main;

        location / {
             root   html;
             index  index.html index.htm;

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
         error_page   500 502 503 504  /50x.html;
         location = /50x.html {
              root   html;

... rest of the file has commented out configuration and closing brackets. root html;

  • cat /tmp/conf/nginx.conf? – quanta Aug 27 '12 at 9:42

[emerg] 23782#0: unknown log format "main" in /tmp/conf/nginx.conf:25

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

Uncomment the log_format line and try again.

  • ok that worked. But the "nginx: [alert] could not open error log file: open() "/home/parth/nginx/var/logs/error.log" failed (2: No such file or directory)" error still remains. Should I be worried about it? – parth Aug 27 '12 at 10:04
  • the only problem is that I deploy this to another directory ... I will probably setup some kind of placeholder which can be replaced using sed. Thanks for the help! – parth Aug 27 '12 at 10:12

Use the error_log config directive.

  • I already tried. It doesn't work. I added "error_log logs/error.log;" to nginx.conf file. – parth Aug 27 '12 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.