I
I
Ivan Petrov2018-08-13 15:51:53
PHP
Ivan Petrov, 2018-08-13 15:51:53

How to set up downloading non-php files in nginx if all requests go to index.php?

I have nginx installed, these are my local site settings

server {
  listen 80;

  root /home/varvoid/php_projects/p1.lo/public;
  index index.php index.html index.htm index.nginx-debian.html;

  server_name p1.lo www.p1.lo;

  location / {
    try_files $uri $uri/ @missing;
      }
    # Rewrite 404s back to PHP

    location @missing {
        rewrite ^ /index.php last;
    }



  # pass PHP scripts to FastCGI server
  
  location ~ \.php$ {

    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    
  }


}

configured so that all requests go to the front controller ( index.php ), but there is also a request to download favicon.ico, which is why my data is inserted into the database twice.
How to set up a site in nginx so that image files are downloaded, more precisely, so that there is an attempt to download the file and not redirect the request to index.php?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lamer350, 2018-08-13
@lamer350

So you should not throw at index.php when you try to open an image.
You have a redirect only if the image does not exist, then check the availability of images at the address.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question