2014-09-20 61 views
0

我是nginx系統的新手,之前我通過this answer的幫助設法訪問了subdomain.domain.com:3000subdomain.domain.com(沒有端口號)。nginx訪問subdomain.domain.com作爲domain.com

我發現在實現以下困難:

我要訪問我的Rails服務器subdomain.domain.com通過domain.com運行。即
當有人在瀏覽器中點擊url domain.com時,它應該充當subdomain.domain.com,但url不應該改變它的瀏覽器。

任何人都可以幫助我如何實現它?

我在/etc/nginx/sites-enabled/default註釋掉默認設置,並創建了 自己設定在/etc/nginx/sites-enabled/myblog爲:

upstream my-app-cluster 
{ 
    server blog.budhram.com:3000; 
} 
server 
{ 
    listen  80; 
    server_name budhram.com; 
    # above not working but if used blog.budhram.com then working but not expected 

    # rails app public folder path 
    root /home/ubuntu/myblog/public; 

    # rails app log file path 
    access_log /home/ubuntu/myblog/log/development.log; 

    location/{ 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 

     if (-f $request_filename/index.html) { 
      rewrite (.*) $1/index.html break; 
     } 
     if (-f $request_filename.html) { 
      rewrite (.*) $1.html break; 
     } 
     if (!-f $request_filename) { 
      proxy_pass http://my-app-cluster; 
      break; 
     } 
    } 
    error_page 500 502 503 504 /50x.html; 
    location = /50x.html { 
     root html; 
    } 
} 
+1

看起來更清晰一些,需要添加'nginx.conf'文件。 – 2014-09-20 11:12:41

+0

@RobertChristopher更新了我的nginx配置文件。 – ram 2014-09-20 11:24:21

回答

0

您可以設置爲代理服務器所需的主機,網址不應該在瀏覽器中改變,但可以改變主機名代理網站上的代碼鏈接:

proxy_set_header Host subdomain.domain.com; 
相關問題