I have an Apache 2.4 VirtualHost on an AWS EC2 instance with the following config:

<Directory /srv/www/example.org>
    Require ip [REDACTED] # Office IP
    Require local

When I make a request from the redacted external office IP address it works fine, but when I make a request from the EC2 instance I get a 401 Unauthorized error. I tried replacing Require local with Require ip to no avail.

The only way I am able to make requests from the local machine is to add its external IP address e.g Require ip

I had a look at the access log and all requests made from the local machine are logged as having come from the external IP address rather than

The /etc/resolv.conf file looks like this:

options timeout:2 attempts:5
; generated by /usr/sbin/dhclient-script
search eu-west-2.compute.internal

Could this be happening because the IP/hostname is being resolved externally by another AWS service?

Can I change any server config so that Apache sees requests from the EC2 instance as being local, so I can use the Require local directive?


The IP address you see in the logs is likely the internal IP address of the ec2 machine.

As an alternative, could you change your require line to use hostname localhost. This should be correctly defined in /etc/hostname

  • Thanks for your answer. The IP address in the logs is actually the external, public IP address of the instance. I changed the require line to Require host localhost but still got the 401 error. – Andy Jan 3 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.