S
S
Sergey Khlopov2021-12-05 12:10:32
Nginx
Sergey Khlopov, 2021-12-05 12:10:32

Have I blocked access to the site for all users and crawlers using deny all?

Hello, please tell me, I just want to make sure I understand everything correctly.
There is this configuration:

server {

    deny  all;
    
    server_name domain.ru;
    root /var/www/user/chroot/domain;
    index index.html index.htm index.php;
   
    location / {
        root /var/www/user/chroot/domain;
        if (!-e $request_filename) {
           rewrite ^/(.*)$ /index.php?q=$1 last;
        }
    }
    location ~* ^.+\.(js|css|svg|jpg|png|ico|pdf|woff2|woff|ttf)$ {
        expires max;
    }

    location = /favicon.svg { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
    
    error_page 404 /index.php;
    
    location ~ \.php$ {
        fastcgi_pass unix:/var/www/user/chroot/tmp/php.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
    location ~ /\.(?!well-known).* {
        deny all;
    }
    
    if ($request_uri ~ "^(.*)index\.(?:php|html)") {
        return 301 $1;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/domain/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

}
server {
  deny  all;
    if ($host = domain.ru) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    server_name domain.ru;
    listen 80;
    return 404; # managed by Certbot
}

This configuration allows you to hide the site from users and search robots due to deny all ? I'm just testing the pages of the site, like yes, I constantly get the 403 code, but maybe I'm missing something.

Thank you in advance for your response.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-12-05
@Shlop

You have something mixed up here - bans, redirects, conditions ... I would refactor, to be honest.
In general, deny allin the absence of directives allowand returnsomewhere else - yes, it will limit the operation of the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question