Как исправить некорректную обработку URL?

При обращении к несуществующей странице с URL определенного типа, в частности, если начало URL представляет собой URL существующей страницы, сервер выдает ответ 200 (ОК) вместо 404 (Not found) и отображает существующую страницу.
Пример:
http://bla-bla.ru/article/nazvanie/abrakadabra/

На сайте используется связка nginx и php-fpm. Подозреваю, что нужно править конфиг nginx, но далеко не знаток в этом. Сайт достался на небольшую поддержку и допилку по дизайну. Подскажите, пожалуйста, в какую сторону копать? Заранее спасибо!

Конфиг nginx:
user www-data;
worker_processes  4;

timer_resolution 100ms;
worker_rlimit_nofile 4096;
worker_priority -5; #Увеличитвваем приоритет

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
	use epoll;
}
http {

    server_tokens off;
    include       /etc/nginx/mime.types;
    access_log  /var/log/nginx/access.log;

    sendfile        on;
    keepalive_timeout  65000;
    tcp_nodelay        on;
    client_max_body_size 50m;

    gzip        on;
	#gzip_min_length     1100;
    gzip_min_length     512;
    gzip_disable        "msie6";  #Быстрее, но работает только на новых версиях nginx
    #gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    gzip_proxied        any;
    gzip_comp_level     5;
    #gzip_types          text/plain application/x-javascript text/xml application/xml text/css;
    gzip_vary           on;
	gzip_buffers 64 8k;
	gzip_http_version 1.1;
	gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/x-javascript application/xml application/xml+rss;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}


server {
    listen 80;
    server_name www.bla-bla.ru;
    return 301 http://bla-bla.ru$request_uri;
}

server {
    listen 80;
    server_name 111.22.333.4;
    return 301 http://bla-bla.ru$request_uri;
}


server {
    listen 80;
    server_name bla-bla.ru;
    #return 301 $scheme://bla-bla.ru$request_uri; 
    server_name 111.22.333.4;
    root /home/hosting/bla-bla.ru/www/;
    index index.php index.htm index.html;
    error_page 404 /404.php;
    error_page 403 /404.php;
    #error_page 403 404;
    access_log /home/hosting/bla-bla.ru/log/nginx/access.log;
    error_log /home/hosting/bla-bla.ru/log/nginx/error.log;
	rewrite ^([^.]*[^/])$ $1/ permanent;


    location /r {
        rewrite ^/r/(.*) /r.php?rub=$1; #301 redirect
    }

    location /category {
        rewrite ^/category/(.*) /category.php?rub=$1; #301 redirect
    }

    location /article {
        rewrite ^/article/(.*) /article.php?rub=$1; #301 redirect
    }
    location /pages {
        rewrite ^/pages/(.*) /pages.php?rub=$1; #301 redirect
    }

    location /author {
        rewrite ^/author/(.*) /author.php?rub=$1; #301 redirect
    }

    location /user {
        rewrite ^/user/(.*) /user.php?rub=$1; #301 redirect
    }

    location /register {
        rewrite ^/register/(.*) /register.php?rub=$1; #301 redirect
    }

    location /main {
        rewrite ^/main/(.*) /main.php?rub=$1; #301 redirect
    }

    location /profile {
        rewrite ^/profile/(.*) /profile.php?rub=$1; #301 redirect
    }

    location /logout {
        rewrite ^/logout/(.*) /logout.php; #301 redirect
    }


    location ~* ^.+.(js|css|png|jpg|jpeg|gif|ico|woff)$ {
        access_log        off;
        expires           max;
    }
    location ~ \.php$ {
        # fastcgi_split_path_info ^(.+\.php)(.*)$;
        # fastcgi_pass   127.0.0.1:9000;
        fastcgi_pass   unix:/var/run/php5-fpm.sock;
        fastcgi_index  index.php;

        fastcgi_param  DOCUMENT_ROOT    /home/hosting/bla-bla.ru/www;
        fastcgi_param  SCRIPT_FILENAME  /home/hosting/bla-bla.ru/www$fastcgi_script_name;
        fastcgi_param  PATH_TRANSLATED  /home/hosting/bla-bla.ru/www$fastcgi_script_name;

        include fastcgi_params;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     off;
        fastcgi_connect_timeout 60000;
        fastcgi_send_timeout 180000;
        fastcgi_read_timeout 180000;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ /\.ht {
        deny  all;
    }

    location /phpmyadmin {

        auth_basic "Enter Super Secret password!";
        auth_basic_user_file /home/hosting/.htpasswd;

        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
            # fastcgi_pass 127.0.0.1:9000;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            fastcgi_connect_timeout 60000;
            fastcgi_send_timeout 180000;
            fastcgi_read_timeout 180000;

            include /etc/nginx/fastcgi_params;
        }
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
        }
    }
    location /phpMyAdmin {
        rewrite ^/* /phpmyadmin last;
    }
}

upstream php {
    server unix:/var/run/php5-fpm.sock;
}
  • Вопрос задан
  • 512 просмотров
Пригласить эксперта
Ответы на вопрос 1
hamnsk
@hamnsk
Системный администратор, Linux/Windows
В location / пропишите

try_files $uri $uri/ =404

либо так

location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}

location "/"
{
index index.php index.html index.htm; # варианты индексных файлов
try_files $uri $uri/ =404; # проверить есть ли файл из запроса на диске, иначе - вернуть ошибку 404
}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы