R
R
Roman2019-02-01 01:09:29
Nginx
Roman, 2019-02-01 01:09:29

Why is 404 given to everything except index.php?

Hello.
I'm trying to deploy a site on DigitalOcean.
I set up nginx and php-fpm according to the manuals, index.php returns correctly, but there is a form on the page that sends an ajax request to the mail.php script, which lies next to index.php.
The problem is that instead of executing mail.php, nginx's 404 file not found is returned.
Here is my nginx config:

server {
        listen 80;
        listen [::]:80;

        root /var/www/site.com/dist;
        index index.html index.php index.htm index.nginx-debian.html;

        server_name site.com;

        location / {
                try_files $uri $uri/ =404;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }

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

What can be done about it?
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
ivankomolin, 2019-02-01
@ivankomolin

Look at the url to which the ajax request is sent.

A
Andrey Burov, 2019-02-01
@BuriK666

see error_log where is nginx trying to find the file?

S
SubGANs, 2019-02-02
@SubGANs

Because you most likely have redirect rules in htaccess, but it is not processed. Check the location /, the error is most likely in the try_files line.
If there is htacess, then look at all sorts of online rule converters from it to nginx, if it is not there, then manually or through Google for your cms or framework

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question