B
B
BloodVIRUS2017-02-03 10:03:35
Nginx
BloodVIRUS, 2017-02-03 10:03:35

How to get 404 error in nginx?

Hello. I'm trying to make my own 404 error for the site, but it doesn't work. It seems that you just need to specify error_page 404 /404.html; and all but no. I still get redirects to the main page .. Here is
my config below:

spoiler
server {
    listen                          80;
    server_name                     site.ru;
    root                            /var/www/site.ru;
    access_log                      /var/log/nginx/domain-access.log;
    error_log                       /var/log/nginx/domain-error.log;
    index                           index.php index.html;
  error_page 404 /404.html;
    rewrite_log                     on;
    location ~* ^/admin/ {
        root					/var/www/user/;

    location ~ \.php$ {
      include                 fastcgi_params;
      fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_pass    backend-valhalla;
    }
    }

    location / {
        try_files               $uri $uri/ @rewrite;
    }
    location /index.html {
        rewrite                 / / permanent;
    }

    location ~ ^/(.*?)/index\.html$ {
        rewrite                 ^/(.*?)/ // permanent;
    }
    location @rewrite {
        rewrite                 ^/(.*)$ /index.php?q=$1;
    }
    location ~ \.php$ {
        include                 fastcgi_params;
        fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass    backend-valhalla;
    }
    location ~* ^.+\.(jpg|jpeg|gif|png|ico|bmp)$ {
        #access_log           off;
        expires                      10d;
        break;
    }
  
    location ~* ^.+\.(css|js)$ {
        #access_log           off;
        expires                      epoch;
        break;
    }

    location ~ /\.ht {
        deny                    all;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Chudnovsky, 2017-02-03
@BloodVIRUS

First you do try_files $uri $uri/ @rewrite; then you do rewrite ^/(.*)$ /index.php?q=$1; and after that you are surprised that index.php is called instead of processing a non-existent page?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question