2

I'm on Apache 2.2.15. My vhost.conf contains a RewriteRule to handle article URLs;

# handling for neat article titles
RewriteRule ^/news/[0-9]{4}/[A-za-z]{3}/([0-9a-zA-Z-]*)/([0-9]{4})([0-9]{6})/?$ "/news/article.cfm?clk=$2&article_id=$3&urltitle=$1" [P,L]

This is working correctly on our live server however on my local development server I'm getting a 502 Error in the browser when I try to load an article:

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /news/2015/news-article/0123012345.

Reason: DNS lookup failure for: localhost.example.com

Apache/2.2.15 (CentOS) Server at localhost.example.com Port 80

This is what I've got in the error log;

[Wed Oct 28 10:00:25 2015] [error] [client 192.168.1.66] proxy: DNS lookup failure for: localhost.example.com returned by /news/2015/news-article/0123012345, referer: http://localhost.example.com/

This leads me to believe that there must be something different in the config of the local server which is causing it problems.

These are the Apache modules I have enabled;

$ apachectl -M | grep proxy
 proxy_module (shared)
 proxy_balancer_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_ajp_module (shared)
 proxy_connect_module (shared)
Syntax OK
$ apachectl -M | grep rewrite
 rewrite_module (shared)
Syntax OK

Sorry if I've left out any pertinent information, grateful for any advice.

sauntimo
  • 153
  • 6
  • 1
    `Reason: DNS lookup failure for: localhost.example.com`... do you have a matching entry in your `/etc/hosts` file? – Gerald Schneider Oct 28 '15 at 10:25
  • @geraldSchneider Yes - the page that lists and links to the news article is on localhost.example.com/news/ and that works correctly. – sauntimo Oct 28 '15 at 10:36
  • Your server disagrees that it works correctly. – Gerald Schneider Oct 28 '15 at 10:36
  • @GeraldSchneider If one page under that domain loads (localhost.example.com/page1), but a different page fails to load under a `RewriteRule` fails (localhost.example/com/page2/rewritten/somewhere) why would it be the /etc/hosts file? There's nothing more complex to add is there, apart from the IP and domain name? – Pete Oct 28 '15 at 11:10
  • @WillshawMedia There is no indication in the OP that it works for some URLs and doesn't for other. The error message clearly indicates a problem resolving the specified host. Without more information about the proxy configuration this is just guesswork. – Gerald Schneider Oct 28 '15 at 11:19
  • @sauntimo's comment stated the page that links to the news article works - but I agree it could have been made clearer. What extra information about the proxy configuration is needed (I'm working with sauntimo on this and as the rule is redirecting successfully on the live server, we're unsure what to compare between live and local setups) – Pete Oct 28 '15 at 11:23
  • aaaah the `/etc/hosts` file was missing the domain - so does the redirect *internally* have to do the DNS lookup? On our live site is it going outside the server and using actual DNS servers to resolve the domain back to the machine? – Pete Oct 28 '15 at 11:29
  • @GeraldSchneider Ah, you're right, I did have a matching entry in /etc/hosts however the ip was wrong as we've recently moved, now that I've fixed it, it's working. Thank you very much for your help - if you post an answer I could accept it? – sauntimo Oct 28 '15 at 11:36

1 Answers1

0

The message

Reason: DNS lookup failure for: localhost.example.com

indicates that the server is unable to resolve the hostname where the proxy module redirects the requests to.

Make sure you have the correct entry in your /etc/hosts file.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89