# goes in /etc/nginx/conf.d
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;
    default_type text/html;

    #access_log  /var/log/nginx/host.access.log  main;

    if ($http_user_agent = "teapot") {
            return 418;
    }

    if ($http_user_agent = "Expanse, a Palo Alto Networks company, searches across the global IPv4 space multiple times per day to identify customers' presences on the Internet. If you would like to be excluded from our scans, please send IP addresses/domains to: scaninfo@paloaltonetworks.com") {
            return 418;
    }

    if ($http_user_agent = "SemrushBot") {
            return 418;
    }

    # Aggressive ByteDance crawler that does not respect robots.txt - see https://youtu.be/Hi5sd3WEh0c
    if ($http_user_agent ~ (Bytespider)) {
            return 418;
    }

    # Rewrite OpenAI to bee movie script
    if ($http_user_agent = "GPTBot") {
            rewrite ^ /bee-movie.txt;
    }

    if ($http_user_agent = "CCBOT") {
            rewrite ^ /bee-movie.txt;
    }
    
    if ($http_user_agent = "ChatGPT-User") {
            rewrite ^ /bee-movie.txt;
    }

    if ($http_user_agent = "GPTBot") {
            rewrite ^ /bee-movie.txt;
    }

    if ($http_user_agent = "Google-Extended") {
            rewrite ^ /bee-movie.txt;
    }

    if ($http_user_agent = "Omgilibot") {
            rewrite ^ /bee-movie.txt;
    }

    if ($http_user_agent = "Omgili") {
            rewrite ^ /bee-movie.txt;
    }

    if ($http_user_agent = "FacebookBot") {
            rewrite ^ /bee-movie.txt;
    }

    if ($http_user_agent ~ (OPX)) {
            rewrite ^ /opx.html;
    }

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }

    location /ip {
        default_type text/plain;
        return 200 "$remote_addr";
    }

    location /ip/json {
        default_type application/json;
        return 200 '{"ip":"$remote_addr"}';
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    #error_page   500 502 503 504  /50x.html;
    error_page   500 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}

    location  /.git {
        # There is no standard way to present options, but in the rare cases that 300 is used it just has a list of links. The Location header is for preferred thing.
        default_type "text/html";
        add_header Location "https://git.askiiart.net/askiiart/askiiart-net";
        return 300 '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body><a href="https://git.askiiart.net/askiiart/askiiart-net">Self-hosted</a><br><a href="https://github.com/askiiart/askiiart-net">GitHub</a></body></html>';
    }

    error_page 300 /error/300.html;
    error_page 301 /error/301.html;
    error_page 401 /error/401.html;
    error_page 402 /error/402.html;
    error_page 403 /error/403.html;
    error_page 404 /error/404.html;
    error_page 406 /error/406.html;
    error_page 410 /error/410.html;
    error_page 413 /error/413.html;
    error_page 417 /error/417.html;
    error_page 418 /error/418.html;
    error_page 423 /error/423.html;
    error_page 425 /error/425.html;
    error_page 429 /error/429.html;
    error_page 451 /error/451.html;
    error_page 502 /error/502.html;
    error_page 508 /error/508.html;
}