Rashp Posted November 2, 2024 at 09:19 PM Share Posted November 2, 2024 at 09:19 PM Всем здравствуйте! Подскажите пожалуйста, как правильно закрыть IP в nginx от прямого доступа? Надоели левые запросы по IP и не повлияет ли это на индексацию? Я сделал следующую конструкцию, не знаю, корректно ли это? server { listen 80; server_name domain.ru www.domain.ru; return 301 https://domain.ru$request_uri; } server { set $host_path "/var/www/webroot"; set $index "index.php"; set $fpm_sock "/run/php/php7.3-fpm-domain.sock"; listen 443 ssl http2; ssl_certificate /etc/nginx/ssl/fullchain.pem; ssl_certificate_key /etc/nginx/ssl/privkey.pem; ssl_trusted_certificate /etc/nginx/ssl/chain.pem; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; add_header X-XSS-Protection "1; mode=block"; add_header X-Frame-Options SAMEORIGIN; add_header X-Permitted-Cross-Domain-Policies master-only; add_header X-Content-Type-Options nosniff; set $domain_name "domain.ru"; server_name domain.ru www.domain.ru; root $host_path/; index $index; default_type text/html; access_log off; error_log /var/www/logs/nginx/error.log crit; if ($host = 'www.$domain_name') { return 301 https://$domain_name$request_uri; } server { listen 0.0.0.0:80 default_server; listen 0.0.0.0:443 default_server; server_name _; return 444; } 0 Quote Link to comment Share on other sites More sharing options...
Rashp Posted November 2, 2024 at 09:37 PM Author Share Posted November 2, 2024 at 09:37 PM но это не верная конструкция ( 0 Quote Link to comment Share on other sites More sharing options...
Rashp Posted November 2, 2024 at 10:34 PM Author Share Posted November 2, 2024 at 10:34 PM (edited) или такой вариант? if ($http_host != "0.0.0.0") { return 301 https://example.ru; } такой вариант тоже не работает (((( Edited November 3, 2024 at 05:57 AM by Rashp 0 Quote Link to comment Share on other sites More sharing options...
Solution 100napb Posted November 3, 2024 at 02:36 PM Solution Share Posted November 3, 2024 at 02:36 PM if ($host = '1.2.3.4') { return 301 https://$server_name$request_uri; } 1 Quote Link to comment Share on other sites More sharing options...
Rashp Posted November 3, 2024 at 03:31 PM Author Share Posted November 3, 2024 at 03:31 PM В 03.11.2024 в 17:36, 100napb сказал: if ($host = '1.2.3.4') { return 301 https://$server_name$request_uri; } Спасибо! помогло ! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.