Score:0

Require ip in apache2 works for index.html but not

li flag

I am using apache 2.4.56 and my site is hosted on Google Cloud Compute. "Require ip ip-number" works for /var/www/html/index.html like mysite.com but it doesn't work for mysite.com/cgi-bin/list_directory_1.cgi?directory=%2CBrasil&submit_directory= In the second case, anybody can access it. This is what I have in the apache configuration file:

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require ip 107.217.8.189
</Directory>

My scripts are in /usr/lib/cgi-bin. How do I allow just one IP to access my scripts?

Thanks!

John Hanley avatar
cn flag
Please review how other posts format data, then update your post. The format of configuration details is important.
Jaromanda X avatar
ru flag
shouldn't you be using `mod_authz_host` rather than `mod_authz_core`? or is Apache documentation misleading?
Marcos Camargo avatar
li flag
I changed to mod_authz_host and restarted apache2 and still doesn't work. Even for my ip I get this: You don't have permission to access this resource.
djdomi avatar
za flag
show the full vhosts config and not just apart from it
Score:0
in flag

You configured the authentication in the context <Directory /var/www/>, so it only applies to files in /var/www. The cgi-bin directory is not inside that directory, so the authentication does not apply.

You should move it to a <Location> context.

<Location />
    Require ip 107.217.8.189
</Location>
Marcos Camargo avatar
li flag
It worked. I placed this directive inside apache2.conf. Is this the correct place? Also, why does "<Location />" require a "/>" at the end instead of just "<Location>"? Thanks!
in flag
There are various places, depending on your needs. If you place it inside a `<VirtualHost>` it will only apply to it, if you place it outside it will apply to all VirtualHosts (if not overridden inside of one). For details see [the documentation](https://httpd.apache.org/docs/2.4/mod/core.html#location).
I sit in a Tesla and translated this thread with Ai:

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.