Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have tried many things but not being able to make error log work, however access log is working fine.

solution mentioned here didn't work for me:

http://mailman.nginx.org/pipermail/nginx/2009-February/009567.html (tried putting error as error_log pram - no luck)

http://forum.nginx.org/read.php?2,58447,58447 (dont have stale process after stopping nginx)

Here is the virtual host info:

server {
        server_name .qa.domain.ca;
        root /var/www/qa.domain.ca;
        access_log /var/log/nginx/qa.domain.ca/access.log;
        error_log /var/log/nginx/qa.domain.ca/error.log;
        index index.html index.htm index.php;

        # redirect to non-www
        if ($host ~* ^www\.(.*)){
                set $host_without_www $1;
                rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
        }

    if (-d $request_filename){
                rewrite ^/(.*[^/])$ /$1/ permanent;
        }
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to index.html
                try_files $uri $uri/ /index.php;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
        location ~ .php$ {
                if (!-f $request_filename) {
                        return 404;
                }
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
                include fastcgi_params;
        }
}
share|improve this question

migrated from stackoverflow.com Jul 16 '12 at 2:32

This question came from our site for professional and enthusiast programmers.

    
When you say it doesn't work do you mean that the file doesn't exist or is it empty ? Also, what version of nginx ? –  Ashray Baruah Jul 14 '12 at 4:48
    
File is empty. However when I delete the error.log file, nginx creates new one, but its always empty even when 500 error occurs due to php script. Thanks :) –  Jay Jul 14 '12 at 22:07
add comment

2 Answers

Your setup, probably based on one of the many dated blog posts out there in the wild, is inefficient.

Here is a better setup:

server {
    server_name www.qa.domain.ca;
    # redirect to non-www
    return 301 http://qa.domain.ca$request_uri;      
}

server {
    server_name qa.domain.ca;
    root /var/www/qa.domain.ca;
    access_log /var/log/nginx/qa.domain.ca/access.log;
    error_log /var/log/nginx/qa.domain.ca/error.log;
    index index.html index.htm index.php;

    # Using "if" for redirection is inefficient as every request will be tested
    # Also, the "-d" test is redundant given the use of "try_files" below

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /index.php;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }
    location ~ .php$ {
        # This "if" block will work as long as every php file physically exists
        # and you don't use a php app that uses rewriting of pseudo files
        # I personally prefer to use "location ~ \..*/.*\.php$ { return 400; }"
        if (!-f $request_filename) {
            return 404;
        }
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
        include fastcgi_params;
    }
}

As for the error_log query, there is no reason why it should not work from either config.

*EDIT* Seems there might be a reason why the logging might not work: https://bugs.php.net/bug.php?id=61045

share|improve this answer
    
Hi Dayo: nginx version: nginx/1.1.19 and I tried working with above mentioned setup, but no luck. Error log file is still empty. My test cases to create errors are by putting 'throw new Exception()' code in php script and writing incorrect php code to cause 500 error. Thanks. –  Jay Jul 14 '12 at 22:10
    
See link to PHP bug in the answer. Are you using PHP-FPM? –  Dayo Jul 15 '12 at 16:53
    
Yes, Php-fpm. Thanks:) –  Jay Jul 15 '12 at 17:41
add comment

Aside from upgrading PHP to the latest version, which should have the fix for the bug you're experiencing, you can also have PHP generate its own error logs. For instance, I have a system where PHP logs to syslog. You can control this with the error_log directive in php.ini.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.