问题
A redirect was created for when returning "404" and go to the first directory of the URL, ex:
foo.com.br/air/uknwfileerror
> foo.com.br/air
But this is not working just for .php
extension
foo.com.br/air/uknwfileerror.php
> foo.com.br/air
listen *:443;
server_name portal-dev.foo.com.br ;
root /var/www/novo;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 20m;
resolver 1.1.1.1;
set $proxy_foops_https 'https://proxy-portal-dev-stg.foo.com.br';
set $proxy_foops_http 'http://proxy-portal-dev-stg.foo.com.br';
ssl on;
ssl_certificate /etc/nginx/ssl/wildcard.crt;
ssl_certificate_key /etc/nginx/ssl/wildcard.key;
access_log /var/log/nginx/dev.foo.com.br.ssl.access.log;
error_log /var/log/nginx/dev.foo.com.br.ssl.error.log;
error_page 404 = @notfound;
location @notfound {
rewrite ^/([\w-]*)/.* https://$server_name/$1/ permanent;
}
add_header Access-Control-Allow-Origin '$http_origin';
add_header Access-Control-Allow-Headers 'origin, x-requested-with, content-type';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Credentials 'true';
location = /portal/{
rewrite ^ https://$server_name/ permanent;
}
location /portal/ {
index index.php index.html index.htm;
try_files $uri $uri/ /portal/index.php?$args;
}
location ~ wp-login\.php$ {
allow all;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location / {
location ~* \.(jpg|jpeg|gif|bmp|ico|png|css|js|swf|woff)$ {
expires 7d;
access_log off;
}
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$args;
fastcgi_intercept_errors on;
}
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location /cas/ {
proxy_pass $proxy_foops_https;
proxy_set_header Host portal-dev.foo.com.br;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X_FORWARDED_PROTO https;
}
location /auth-service {
proxy_pass $proxy_foops_https;
proxy_set_header Host portal-dev.foo.com.br;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_set_header X_FORWARDED_PROTO https;
}
}
using Curl -I
I see that it is returning 301 with the url foo.com.br/air/uknwfileerror.php
but with the path foo.com.br/air/uknwfileerror
it returns only 200 and I dowload the home page.
The expected one is that when entering a path that of 404, also returns to the first block typed:
foo.com.br/air/uknwfileerror.php
> foo.com.br/air
foo.com.br/air/uknwfileerror
> foo.com.br/air
来源:https://stackoverflow.com/questions/55589837/how-to-insert-read-path-in-try-files-rewrite-error-in-nginx