I'm a bit confused. I have nginx running on a port other than 80.
# part of nginx.conf
server {
listen 7000;
include /etc/nginx/my_app.conf;
}
That's because my HAProxy is running on 80 on the same server.
# Approximate haproxy.cfg
listen foo 0.0.0.0:80
option forwardfor
server web01 web01:7000 maxconn 25000 check
How do I make nginx serve a redirect from www.example.com to example.com?
I tried the following, but nginx complains that it can't listen on 80 (which makes sense, since haproxy is listening there.)
server {
server_name www.example.com;
rewrite ^ http://example.com$request_uri? permanent;
}
Figured it out. Since nginx cascades down the defined servers, I can add a more specific server declaration above the one I had. In my case it's the following.
I can have multiple declaration listening on the same port, but the first one will catch the www subdomain and serve a redirect, while the second one actually serves the app.