Wednesday, February 15, 2012

Reverse proxy setting for Nginx to route by domain name

Purpose:
1, Assuming the server will own 2 domain names: www.aaa.com and www.mysite.com
You should get same IP address while ping these 2 domain names.
2, By default, when you visit www.aaa.com. it will redirect to www.google.com
3, If you visit domain name www.mysite.com, you will get the response from web server serving on 10.1.1.47:8081.
   1: server
   2: {
   3:         listen 80;
   4:         server_name ~^(www\.)?(?<domain>.+)$;
   5:  
   6:         location / {
   7:                 #default redirect
   8:                 proxy_pass http://www.google.com;
   9: 
  10:                 #redirect by domain name.
  11:                 if ($domain ~* mysite)
  12:                 {
  13:                         proxy_pass http://10.1.1.47:8081;
  14:                 }
  15:               proxy_set_header Host $host;
  16:                 proxy_set_header X-Real-IP $remote_addr;
  17:                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  18:         }
  19:         access_log      /var/log/nginx/rproxy.access_log;
  20:         error_log       /var/log/nginx/rproxy.error_log;
  21:  
  22: }

绘图1

2 comments:

  1. When it comes to browsing over the internet, the first and the far most important thing that one should consider is protecting your private and personal information over the internet or make maximum efforts to save his personal data and other information from the hackers one should consider going with using a proxy address rather than his own IP address. Bonuses

    ReplyDelete
  2. Why is it important for you to choose a domain name you are happy with? You need to realize that once you start your business and/or have a lot of customers you will not be able to change your domain name. Namecheap domain registration coupon

    ReplyDelete