1

The goal is to load pages from blog.example.com/blog using example.com/blog and all the posts, categories and authors.

location /blog(/.*)$ {
  rewrite ^ $1 break;

  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_pass https://blog.example.com/blog$1;
  proxy_ssl_server_name on;
}

Gives a 500 error

2
  • If blog.example.com is publicly reachable, this will lead duplicate content, which is bad for SEO. You need to at least set canonical URLs properly. – Tero Kilkanen Feb 5 at 15:44
  • @TeroKilkanen that has all been handled – Volkan Kaya Feb 5 at 18:15
0

If the URI is passing through unchanged (e.g. /blog/foo -> /blog/foo) then you do not need a rewrite and you do not need the optional URI part on the proxy_pass statement. See this document for details.

The syntax of your location statement is wrong. You are using a regular expression without the appropriate operator ~ or ~*. However, you do not need to use a regular expression to match all URIs that begin with /blog. See this document for details.

For example:

location ^~ /blog {
    proxy_set_header Host              $host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass https://blog.example.com;
    proxy_ssl_server_name on;
}
3
  • I got failed (24: Too many open files) while connecting to upstream, client: 1.2.3.4, server: example.com, request: "GET /blog – Volkan Kaya Feb 5 at 18:20
  • It sounds like it's trying to connect to itself. Are you sure that these are two distinct servers. – Richard Smith Feb 5 at 18:24
  • Yes currently same server, but end goal would be two different servers – Volkan Kaya Feb 5 at 18:27

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.