Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
943 views
in Technique[技术] by (71.8m points)

nginx reverse proxy multiple backends

Here is my situation: I will have one frontend server running nginx, and multiple backends servers running apache + passenger with different rails applications. I am NOT trying to do any load balancing. What I need to do is setup nginx to proxy connections to specific servers based on the url. IE, client.domain.com should point to x.x.x.100:80, client2.domain.com should point to x.x.x.101:80, etc.

I am not that familiar with nginx, but I could not find a specific configuration online that fit my situation.

Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can match the different URLs with server {} blocks, then inside each server block, you'd have the reverse proxy settings.

Below, an illustration;

server { 
  server_name client.domain.com;

  # app1 reverse proxy follow
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://x.x.x.100:80;

}

server { 
  server_name client2.domain.com;

  # app2 reverse proxy settings follow
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_pass http://x.x.x.101:80;
}

Also, you may add further Nginx settings (such as error_page and access_log) as desired in each server {} block.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...