We want to duplicate our website (yes, we are aware duplicated content). domain-a.com needs to be available also as domain-b.com.

My config looks like this:

server {

  listen 80;
  server_name www.domain-b.com;

  location / {
    autoindex off;
    proxy_buffering   off;
    # rewrite  (.*) /$1 break;
    proxy_pass;  # Cloudflare
    proxy_set_header Host www.domain-a.com;
    proxy_redirect    default;


This works for www.domain-b.com/. However www.domain-b.com/info/aboutis returning 503. Same for /test.jpg

How exactly can we proxy literally everything?

  • Why not just define an additional server_name or let it use the same root directory? If you get a 503 have you checked your logs to see what's actually happening?
    – Seth
    Jan 11, 2017 at 7:31
  • that's not an option. needs to be "mirrored" and then also replaced a little content. serverlog actually is empty /access.log and /errors.log Jan 11, 2017 at 8:01
  • If you don't see the error 500 in any of the logs chances are you're looking either at the wrong nginx logs or the wrong logs all together. That 500 might be thrown by your PHP engine or whatever is driving the original site so you should look into those logs as well.Iif you need to replace content how do you expect it to work by using a reverse proxy?
    – Seth
    Jan 11, 2017 at 9:13
  • well, i did it myself now with Sinatra (Ruby). just take the incoming querystring, forward to the other server, replace some content in the body and return that body. easy game. mod_substitute would do the same on proxy level but since i'm a programmer and not a admin i stick to my app now Jan 12, 2017 at 1:12
  • 1
    Do you expect this solution to be maintainable? I'd still suggest a fork or setting up proper configuration options and running an independent version. It would be way clearer but it's your application. You could try to write an answer based on what you did and accept it.
    – Seth
    Jan 12, 2017 at 6:34

2 Answers 2


The solution would have been:

server_name www.domain-a.com www.domain-b.org;

or just

server_name *;

plus this

proxy_set_header        Host $host;

which leaves it dynamic.

503 Bad gateway usually refers to a non-reachable upsteam server. Not necessarily something wrong with the config. Could also have been the wrong X-Forwarded-Host header from the proxy_set_header which was static and cloudflare declined serving it.


my answer is a little different solution.

we ended up creating our own "proxy" based on ruby/sinatra, including cookie handling.

get /(.*)/ do
  if (asset? || download?) && !exception?
    return redirect to(target_url), 301

    agent = Mechanize.new
    cookies.each.map{ |k,v| agent.cookie_jar << Mechanize::Cookie.new(name: k, value: v, domain: ".we.us", path: "/") }

    response = agent.get(target_url)

    agent.cookies.map{ |cookie| cookies[cookie.name] = cookie.value }

    send("modify_#{target}", response.body)

  rescue Mechanize::ResponseCodeError
    p "throw a 404!"
    status 404

def asset?
  # binding.pry
  extensions = %W(.jpg .png .gif .jpeg .ico .woff .ttf .gif .woff2 .cur)
  url = target_url
  url = url.split("?").first

def target_url
  target_host + query_string

def query_string
  # binding.pry
  if env["PATH_INFO"] == "/"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .