Block direct IP access

Discussion in 'Installation/Configuration' started by WolfgangPue, Nov 8, 2018.

Tags:
  1. WolfgangPue

    WolfgangPue New Member

    I want that the domain is only accessible with the domain name. But if I enter the IP address in the browser address line the site also appears.

    To block direct IP access an additional server block is needed for http. So I copied the nginx_vhost.conf.master to the conf-custom directory and added the following block at the beginning. ISPConfig generates the new nginx config file but it puts to <domain>.vhost_err

    server {
    listen <tmpl_var name='ip_address'> default_server;
    server_name _;
    return 404;
    }

    But the new syntax is correct. When I put the generated code to the <domain>.vhost manually and reload the nginx server, the site is working as expected (block direct IP access).

    Is there another option to block direct IP access on nginx server or why throws ISPConfig an error with a correct syntax?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    When a file is saved with .err ending, then nginx did not start with it. rename the vhost file to .vhost_bak, then rename the vhost_err file to .vhost and restart nginx to see the error on the shell and in the nginx log file.
     
  3. WolfgangPue

    WolfgangPue New Member

    Thanks for the info. I just copied the new server block to the vhost file and nginx started without problems.
    When I test the whole err file with nignx following error occurs:

    nginx: [emerg] duplicate location "/stats/" in /etc/nginx/sites-enabled/100-<domain>.vhost:111

    I had set following nginx directives for the domain:

    # webstats
    location /stats/ {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
    }

    Without the second server block ispconfig replaces the original location block with the one in the directives and there is no error.
    When I add a second server block to the conf-custom/nginx_vhost.conf.master both locations blocks for /stats/ are in the file:

    location /stats/ {
    index index.html index.php;
    auth_basic "Members Only";
    auth_basic_user_file /var/www/clients/client2/web1/web//stats/.htpasswd_stats;
    }

    location /stats/ {
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
    }

    I commented out the original location block in conf-custom for /stats/ and now everything is working fine.
    Don't know why ISPConfig replaces the /stats/ block in the orignal file but not in the custom file when there is a second server block.
     
  4. WolfgangPue

    WolfgangPue New Member

    Ok, the additional server block makes probelms if I use the same IP twice for a webId, because than the server block is identical and I get a duplicate error. I use following method in the nginx_vhost,conf.master file now.

    if ($host = "<tmpl_var name='ip_address'>") {
    return 444;
    }
     

Share This Page