0

have this .conf file to my website, but everytime it should redirect to 404 page it says file not found, however if it goes to a normal page it works always.

server {
    listen 80;
    server_name mywebsite.com;
    client_max_body_size 50M;
    root /var/www/html;
    index index.php index.html index.htm;
    location / {
        try_files $uri $uri/ @rewrite;
    }
    location @rewrite {
        rewrite ^/(.*)$ /$1.php last;
    }
    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass php:9000;
        fastcgi_param SCRIPT_FILENAME /var/www/html/$server_name$fastcgi_script_name;
    }
    error_page 404 /404.php;
    location = /404.php {
        internal;
        include fastcgi_params;
        fastcgi_pass php:9000;
        fastcgi_param SCRIPT_FILENAME /var/www/html/$server_name/404.php;
    }
}

i just dont know why it says file not found, when i open the file directly http://mywebsite.com/404.php it works just fine

1
  • 1
    You state that http://mywebsite.com/404.php works, but it shouldn't as location = /404.php matches the URL but is marked internal. Use sudo nginx -T (uppercase T) to view the entire configuration across all included files and ensure that the configuration appears as stated in your question. Also, check the access log and error log for any related messages. Commented May 20 at 15:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.