I got strange Nginx behavior while trying to make site config. I need Nginx to use article.php
in case the file is missing on server. But it works strange. If the query is example.com/snaff
, it gets redirected to article.php
. But if the query is example.com/snaff.php
it just throws 404 error in browser.
I use Ubuntu 20.04 + Nginx 1.18.0. Earlier the same config worked ok on Ubuntu 18.04 + Nginx 1.19.0.
Can't understand what's going wrong.
Here is the config code.
server {
listen 80;
server_name example.com www.example.com;
#return 404; # managed by Certbot
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
}
server {
listen 443 ssl http2;
server_name example.com www.example.com;
root /var/www/example.com/public_html/;
index index.php index.html index.htm;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
access_log /var/log/nginx/example_access.log;
error_log /var/log/nginx/example_error.log error;
etag on;
gzip on;
gzip_comp_level 5;
gzip_min_length 10;
gzip_proxied any;
gzip_types *;
gzip_disable "msie6";
client_max_body_size 15m;
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
add_header Cache-Control "no-store, no-cache, must-revalidate";
}
location ~ /\.ht {
deny all;
}
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /article.php;
}
}