Nginx configuration 404 errors
I must say that the server configuration is only superficial, perhaps the problem is trivial. But I would be very grateful for your help. I got the site for finishing the design and a small revision. The server uses a bundle of nginx and php-fpm. The situation (sorry for the design, the reputation for links was not enough):
- при переходе по ссылке http://blabla.ru/blublu.php - уходит на
http://blabla.ru/404.php
- при переходе по ссылке http://blabla.ru/blublu.pdf - ничего не
происходит и отображается главная http://blabla.ru, хотя в адресной
строке http://blabla.ru/blublu.pdf
- при переходе по ссылке http://blabla.ru/asfasflkjw1312kl (т.е. вбитый
абсолютный бред) - ничего не происходит и отображается главная
http://blabla.ru, хотя в адресной строке http://blabla.ru/asfasflkjw1312kl
As I understand it, when requesting any non-existing link, whether it is a link to a file or to absolute nonsense, there must be either a redirect to 404.php. But this one it's not happening. How to fix it? I apply the nginx settings. Thank you in advance for your answer.
user www-data;
worker_processes 4;
timer_resolution 100ms;
worker_rlimit_nofile 8192;
worker_priority -5; #Увеличитвваем приоритет
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
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_disable "msie6"; #Быстрее, но работает только на новых версиях nginx
#gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_proxied any;
gzip_comp_level 4;
gzip_types text/plain text/css application/x-javascript text/xml application/xml $
gzip_vary on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
Configuration file from sites-enabled:
server {
listen 80;
server_name www.blabla.ru;
return 301 http://blabla.ru$request_uri;
}
server {
listen 80;
server_name XXX.XX.XXX.X;
return 301 http://blabla.ru$request_uri;
}
server {
listen 80;
server_name blabla.ru;
#return 301 $scheme://blabla.ru$request_uri;
server_name xxx.xx.xxx.x;
root /home/hosting/blabla.ru/www/;
index index.php index.htm index.html;
error_page 404 /404.php;
#error_page 403 404;
access_log /home/hosting/blabla.ru/log/nginx/access.log;
error_log /home/hosting/blabla.ru/log/nginx/error.log;
location / {
if (!-e $request_filename){
rewrite ^/(.*) /index.php?$query_string; #301 redirect
}
}
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)$ {
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/blabla.ru/www;
fastcgi_param SCRIPT_FILENAME /home/hosting/blabla.ru/www$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED /home/hosting/blabla.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;
}
}
1 answers
This block "works" on requests /blublu.pdf
(as I understand, there is no such file in the root of the site) and /asfasflkjw1312kl
, translating the request into an appeal to /index.php
:
location / {
if (!-e $request_filename){
rewrite ^/(.*) /index.php?$query_string; #301 redirect
}
}
If you don't want this behavior, just comment out this block.