4

I have a load balancer (Nginx) and another Apache server which is hosting a wordpress blog (at /blog). I want all my traffic on my load balancer at /blog to go to this Apache server. I have the following settings:

upstream main_app  {
  server main_app_address;
}

upstream blog {
  server blog_address;
}

server {
   server_name appname.com;
   return 301 http://www.appname.com$request_uri permanent;
}

server {
  listen 80;
  server_name appname.com;

  location / {
    client_max_body_size 8M;
    proxy_pass  http://main_app;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Scheme $scheme;
  }

  location /blog {
    proxy_pass http://blog/;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Scheme $scheme;
  }

}

This shows me the directory listing on the Apache server at / where I can see the /blog however that is not what I want, I want it to show the contents of /blog from the Apache server.

If I remove the trailing slash in the /blog location directive I end up with endless redirects.

How do I solve this?

Jasdeep Singh
  • 237
  • 1
  • 4
  • 8

2 Answers2

3

You can solve this by replacing:

proxy_pass http://blog/;

with

proxy_pass http://blog;

Please read the docs: http://nginx.org/r/proxy_pass

VBart
  • 8,309
  • 3
  • 25
  • 26
0

I had similar issue and it was solved when I commented out proxy_set_header Host $host;

Mojtaba Rezaeian
  • 451
  • 5
  • 14