V
V
Vladimir Zp2018-05-24 16:41:21
Nginx
Vladimir Zp, 2018-05-24 16:41:21

Redirecting in Nginx from a non-existent url to an existing one?

Good afternoon. I noticed a strange behavior of ngixn on one of the sites, which I did not specifically configure. For example, if you type a non-existent address - h_ttp://site.ru/monitor , a 301 redirect occurs and the page h_ttp://site.ru/monitor ing -zabbix opens. If you type an address that cannot be converted to an existing page by adding characters, then a 404 error occurs.
Can someone tell me which nginx parameter is responsible for this behavior? The site is proxied from one server to another. First server config:

server {
    listen 80;
    server_name site.ru www.site.ru;
    access_log /var/log/nginx/site/access.log;
    error_log /var/log/nginx/site/error.log;
    return 301 https://$server_name$request_uri;
    }

server {
    listen 443 ssl http2;
    server_name site.ru;
    access_log /var/log/nginx/site/ssl-access.log;
    error_log /var/log/nginx/site/ssl-error.log;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/site.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/site.ru/privkey.pem;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;

    location /.well-known/acme-challenge/ {
    root /web/sites/site.ru/www/;
    }
    location / {
    proxy_pass http://10.10.10.4;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    }

    location ~* ^.+.(js|css|png|jpg|jpeg|gif|ico|woff)$ {
    access_log off;
    proxy_pass http://10.10.10.4;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    }
}

The second server, where the site itself:
server {
    listen 80;
    server_name site.ru;
    root /web/sites/site.ru/www/;
    index index.php index.html index.htm;
    access_log /web/sites/site.ru/log/access.log main;
    error_log /web/sites/site.ru/log/error.log;

    keepalive_timeout		60;
    set_real_ip_from 10.10.10.2;
    real_ip_header X-Real-IP;

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

    location ~* ^.+.(js|css|png|jpg|jpeg|gif|ico|woff)$ {
    access_log off;
    expires max;
    }

    location ~ \.php$ {
    try_files  $uri =404;
    fastcgi_pass   unix:/var/run/php-fpm/site.sock;
    fastcgi_index index.php;
    fastcgi_param DOCUMENT_ROOT /web/sites/site.ru/www/;
    fastcgi_param SCRIPT_FILENAME /web/sites/site.ru/www$fastcgi_script_name;
    fastcgi_param PATH_TRANSLATED /web/sites/site.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_param HTTPS on;
    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort off;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    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;
    }
}

server {
     listen 80;
     server_name  www.site.ru;
     rewrite ^ http://site.ru$request_uri? permanent;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question