Status 404: ZF3 and Nginx

Viewed 166

Nginx is giving me a 404 on my Laminas application when I try to navigate anywhere other than the base URL; from the looks of my log, it seems it is trying to serve routes as files/directories.

I used the information in the Laminas MVC skeleton's README to configure my VH; it looks to me like it should be passing the route to the public directory's index.php, but for some reason it is not.

Here is my configuration (/etc/nginx/sites-available/domain.com):

server {
    listen 80 default_server;
    listen [::]:80 default_server;
 
    root /sites/domain.com;
 
    index index.php
 
    server_name domain.com;
 
    location / {
        index index.php
        try_files $uri $uri/ @php;
    }
 
    location @php {
        # Pass the PHP requests to FastCGI server (php-fpm) on 127.0.0.1:9000
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME /sites/domain.com/index.php;
        include fastcgi_params;
    }
    
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
    
        # With php-fpm (or other unix sockets):
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
    }
}
1 Answers

Try This,

  • a location block to try all php, uris and html files (while keeping query string params)
  • a single php block, passing to your fpm sock
server {
    listen 80 default_server;
    listen [::]:80 default_server;
 
    root /sites/domain.com;
 
    index index.php
 
    server_name domain.com;


    location / {
            try_files $uri $uri/ /index.html /index.php$is_args$args;
    }
         

  location ~ \.php$ {
          fastcgi_pass  unix:/var/run/php/php7.4-fpm.sock;
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include       fastcgi_params;
     }
}
Related