0
<VirtualHost *:80>
    ServerAdmin example.com
    DocumentRoot "C:/xampp/htdocs/example.com"
    ServerName www.example.com
    ServerAlias example.com
    ErrorLog "logs/example.com-error.log"
    CustomLog "logs/example.com-access.log" common


  
     <Directory "C:/xampp/htdocs/example.com">
    
            Options All -Indexes 
            AllowOverride All



 <RequireAll>
    
    Require all denied
    Require ip 49.204.11.24
    
    </RequireAll>
            

    </Directory>
   </VirtualHost>

1 Answers1

0

Assuming you are using Apache 2.4, your syntax is correct. Just check your loaded modules and make sure that you have loaded the authz_core module.

To check the module is loaded use:

apache2ctl -M

Since my assumption is this webserver might have some other websites that may be needed to be visible by others, thus it's best to apply this restriction at the virtual hosts level and not globally.

<VirtualHost *:80>
        
        ServerName www.example.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Location />
        Require ip 172.20.131.34
        </Location>
</VirtualHost>

So by the above configuration, only 172.20.131.34 as source ip, is able to view my page, and others will get the Forbidden message while accessing the page.

Zareh Kasparian
  • 753
  • 5
  • 20
  • Yes I'm using Apache 2.4. Thanks for the help! – NARESH RAMINI Mar 19 '22 at 10:48
  • Yes upon checking the configuration (httpd.conf) file, authz_core module is asked to be loaded. Yet the above code doesn't work as expected. – NARESH RAMINI Mar 19 '22 at 11:08
  • The above code denies all the ips including the one that's allowed. – NARESH RAMINI Mar 19 '22 at 11:11
  • And the loaded modules were also checked, by typing the command "httpd -M" in xampp shell, it listed the module named "authz_core_module". I'm unable to find what's wrong with the above code. – NARESH RAMINI Mar 19 '22 at 11:22
  • @Naresh check the configuration added to the Answer section. – Zareh Kasparian Mar 19 '22 at 11:52
  • I'm using xampp on windows 10; and the command that worked to pull the loaded modules was this => "httpd -M". Is this wrong?? But it did fetched the loaded modules. And I'm trying to apply my configuration inside Directory Directive for a website directory that's enclosed by it's path, inside it's opening tag; I haven't applied that configuration globally. Thank you very much @Zareh Kasparian – NARESH RAMINI Mar 19 '22 at 13:24