I successfully able to setup nginx and apache combination to serve wordpress blog with the help of this site. I exactly followed all the codes supplied in that site and following is the directory strcture of my blog and sub-blog.


I have no problems at all while surfing (main.com) but sometimes, if I call


the browser is redirected to


and got "Cannot connect to server" error from browser. "8080" is used as proxy port where nginx transfer all dynamic content traffics to Apache. But if I type this http://main.com/mainBlog again in the same address bar, problem disappear again. It would be annoy to users who doesn't know to reload the page without "8080" port.

Edit: I just found out that, if I leave slash at the end of the url, I got that problem but if I put slash, no problem at all. Where can I define for that problem?


This is actually Apache (or PHP) sending the redirect, so you need to fix it there, you cannot change this in Nginx unless you want to actively make nginx redirect no trailing slash to trailing slash.

rewrite ^(.*[^/])$ $1/ permanent; will do it.

  • Thanks a lot Martin. Would u mind if I ask where to put that line? I'm not very good with server things and still learning. – Devyn Jul 8 '11 at 18:43
  • Hi! I suggest you read this: wiki.nginx.org/Quickstart If you still have questions afterwards then go ahead and ask. – Martin Fjordvald Jul 8 '11 at 22:54

I had a similar problem with varnish and nginx (varnish on port 80 proxying to nginx listening on 8080) and needed to add "port_in_redirect off;" ... server_name_in_redirect needed to stay on so nginx knew which host it was handling.

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.