I’ve been trying to get this to work for a while now, but I’m failing manifold.
I have the following configuration:
server {
listen 8081;
server_name name.of.server.en;
root /path/to/api;
index index.php;
location ~ .php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/([A-Za-z0-9]+)/$ /index.php?data=$1? last;
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/$ /index.php?data=$1&id=$2? last;
return 404;
}
}
nginx -t
says that everything is ok. But as soon as I call the URL I always get a 404 Not Found
.
I have no idea what I am doing wrong. Probably something completely banal, but I can’t figure it out.
I am almost at the despair.
2
Answers
Here is what I am running for PHP7.4 for local testing. Might be helpful to you.
The order is important at this point.
This is how it should work: