Score:0

Configuring virtual hosts; Need to just allow one ip address to access the website and deny all. What's wrong with the below code?

cn flag
<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>
Score:0
us flag

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.

Naresh avatar
cn flag
Yes I'm using Apache 2.4. Thanks for the help!
Naresh avatar
cn flag
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 avatar
cn flag
The above code denies all the ips including the one that's allowed.
Naresh avatar
cn flag
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.
Zareh Kasparian avatar
us flag
@Naresh check the configuration added to the Answer section.
Naresh avatar
cn flag
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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.