0

I have simple nginx configuration

server {
  listen 80;
  listen [::]:80;
  server_name test.mydomain.com;
  location / {
    add_header Content-Type text/plain;
    return 200 'we are at least here';
  }
}

and an A record pointing to my test subdomain on an instance (e.g. IP 10.0.0.2)

netstat -tlpn output is the following

tcp        0      0 10.0.0.2:443        0.0.0.0:*               LISTEN      21756/nginx: master
tcp        0      0 10.0.0.2:1500       0.0.0.0:*               LISTEN      6315/ihttpd
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      22751/apache2
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21756/nginx: master
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      942/sshd
tcp6       0      0 ::1:953                 :::*                    LISTEN      912/named
tcp6       0      0 1a02:4f8:c2c:3f80:::443 :::*                    LISTEN      21756/nginx: master
tcp6       0      0 :::80                   :::*                    LISTEN      21756/nginx: master

and locally I'm able to do curl -H "Host: test.mydomain.com" http://127.0.0.1/ and receive a proper response.

But when accessing the same via browser it got redirected to one of the apache's virtualhosts (apache2ctl -S) which is

127.0.0.1:8080         is a NameVirtualHost
         default server wrongdomain.com (/etc/apache2/vhosts/wrongdomain.com/wrongdomain.com:1)

It seems to me like nginx should be serving requests to my domain and return the page, but for some reason apache is handling that. I can confirm by systemctl stop apache2 and seeing 502 Bad Gateway error from nginx.

How to debug this error and how to tell nginx not to proxy requests to be handled by apache?

8
  • 1
    Do you have reverse proxy configuration to Apache in some other block in nginx or is Apache only listening on 8080 and not routed by any other means? – taleodor Feb 18 at 22:04
  • No, Apache is only listening on 8080, that's why it confuses me - it's not a behaviour I would expect in such a case – Most Wanted Feb 19 at 8:02
  • It may a silly problem. Make sure you restarted the Nginx by nginx -s reload or even service nginx restart. Then if you did before, check out the caches of the browser. I just tested your Nginx conf with another server_name and it's worked like a charm. – M. Rostami Feb 19 at 12:35
  • @M.Rostami have done that already, doesnt help – Most Wanted Feb 19 at 12:59
  • If it only listens on 8080, means that request from the browser goes to 8080 - no other explanation. How, it's not yet clear though. What is the exact request you're making in the browser? Finally, consider trying tcpdump to figure it out. – taleodor Feb 19 at 13:47

Your Answer

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

Browse other questions tagged or ask your own question.