I'm on CentOS 7, EasyApache 4. I have some .htaccess rewrites that look like:

RewriteRule ^slug/(.*)$ http://mybucket.s3-website-us-east-1.amazonaws.com/slug/$1? [P,L]

in order to rewrite requests for static files to my s3 bucket. This works fine, until I reboot the server, then it stops working. Apache is running, and the website loads, but all requests to files at /slug get 404s. But, if I then manually restart apache, it starts working again and the images load. I'm using the [P] tag so that all files are under the SSL certificate on my local server.

Any idea what might be going on here? Even if you have a hint for how to begin troubleshooting this, that would help me a lot. Thanks!

  • I found in the apache error logs, that for each proxied image, I'm getting [proxy error] ... DNS lookup failure for: (my s3 url) – user339568 Jul 1 '17 at 19:41
  • How do you resolve your addresses ? External dns ? – Pierre-Alain TORET Jul 1 '17 at 19:44
  • I haven't done anything on the server to change whatever the default way a CentOS server would resolve external addresses. I suppose it would check some local cache or hosts file, and then query an external DNS server if the host wasn't found. I guess my problem is, my server can't resolve the URL to my s3 bucket, unless I restart apache, then it will. – user339568 Jul 1 '17 at 19:48
  • Before restarting apache can you resolve the domain from the system ? – Pierre-Alain TORET Jul 1 '17 at 20:05
  • I can ping the s3 url from the command line, and I get a response. Any other way I can check that? – user339568 Jul 1 '17 at 20:17

Looks like your EasyApache starts before network. This cause error DNS lookup failure. As workaround, you could add address of your S3 bucket in /etc/hosts file or add After=network.target remote-fs.target nss-lookup.target to [Unit] section in service file, to start EasyApache after network is up, as it done in Apache service file.

| improve this answer | |
  • Sounds like a good reason for having DNS lookup failure, but how can apache start before ? Isn't it supposed to do some binding on the network interface ? – Pierre-Alain TORET Jul 2 '17 at 19:48
  • @daftaupe if it binds on it's possible. – Alexander Tolkachev Jul 2 '17 at 19:49
  • I can't add the ip address of the s3 bucket, because s3 buckets don't have static ip addresses. But, even if apache starts before network on reboot, shouldn't apache be able to resolve the address after reboot is completed and network has started up? I'm observing DNS lookup failures indefintely, until I restart apache. – user339568 Jul 3 '17 at 4:24
  • Also, what is the service file that you're referring to where I would add the line you suggested? – user339568 Jul 3 '17 at 14:56
  • @user339568 it should be /usr/lib/systemd/system/httpd.service. – Alexander Tolkachev Jul 3 '17 at 16:45

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.