0

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 http://104.25.206.103;  # 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?

6
  • 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 '17 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 – Tim Kretschmer Jan 11 '17 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 '17 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 – Tim Kretschmer Jan 12 '17 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 '17 at 6:34
1

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.

0

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
  end

  begin
    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)

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

    content_type(response.response['content-type'])
    send("modify_#{target}", response.body)

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

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



def target_url
  target_host + query_string
end

def query_string
  # binding.pry
  #params['captures'].first
  if env["PATH_INFO"] == "/"
    "/"
  else
    env["REQUEST_URI"].scan(Regexp.new("#{env["PATH_INFO"]}.*")).first 
  end
end

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.