nginx-ultimate-bad-bot-blocker icon indicating copy to clipboard operation
nginx-ultimate-bad-bot-blocker copied to clipboard

[INSTALLATION] How to use with default.conf that redirects all HTTP -> HTTPS traffic

Open cca32 opened this issue 2 years ago • 2 comments

Awesome package! Works great. This is a very silly question as my knowledge of nginx isn't very strong.

I have the following default.conf:

# routes all http to https
server {
    listen 80;
    listen [::]:80;

    server_name _;
    server_tokens off;

    ##
    # Nginx Bad Bot Blocker Includes
    # REPO: https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
    ##s
    include /etc/nginx/bots.d/ddos.conf; 
    include /etc/nginx/bots.d/blockbots.conf;
    
    location / {
        return 301 https://$host.com$request_uri;
    }
}

So it works for all HTTP traffic. I then have other .conf files with the corresponding https traffic which do not get protected. Am I using nginx design in an anti-pattern way?

What would be the best way to redirect all http traffic to https , and only have to provide the appropriate include files only once?

Thanks!

cca32 avatar Mar 03 '23 22:03 cca32

Just add the includes to both your port 80 and port 443 config files/blocks. This will reject / block traffic on both ports so in many cases rejecting traffic on port 80 before it even reaches port 443.

mitchellkrogza avatar Mar 04 '23 05:03 mitchellkrogza

Yep that makes sense and is my current approach. Is there a way to structure the nginx files so that the include directive is only used once?

Let's say I have 3 subdomains each with a 443 conf file.

Is it necessary to have a 443 block with include directives for every domain? Or is it possible to apply the include at some larger level that each 443 server block inherits or something

Thanks so much! Great package

cca32 avatar Mar 04 '23 13:03 cca32