2013-09-24 67 views
2

我是nginx新手。我正在嘗試將GitLabs安裝在現有的PHP項目旁邊,該項目目前由Apache在端口80上提供服務。我的計劃是讓它們在端口90上並排工作,然後關閉Apache,將兩個項目都切換到端口80上的Nginx爲什麼Nginx將所有流量路由到一個子域?

好的。問題是這兩個子域名都被我的php項目的server所捕獲,只能用於請求db.mydomain.com。對於php項目,我有一個名爲ccdb的文件,鏈接到/etc/nginx/sites-enabled。它包含:

server { 
    server_name db.mydomain.com; 
    listen 90; ## listen for ipv4; this line is default and implied 
    #listen [::]:80 default ipv6only=on; ## listen for ipv6 

    root /var/www/ccdb; 
    index index.html index.htm index.php; 
} 

然而,出於某種原因,流量git.mydomain.com正在從服務器D /var/www/ccdb即使我已經沿着符號鏈接是一個另一個文件名爲gitlab與此內容:

# GITLAB 
# Maintainer: @randx 
# App Version: 5.0 

upstream gitlab { 
    server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; 
} 

server { 
    listen 90;   # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea 
    server_name git.mydomain.com;  # e.g., server_name source.example.com; 
    server_tokens off;  # don't show the version number, a security best practice 
    root /home/git/gitlab/public; 

    # individual nginx logs for this gitlab vhost 
    access_log /var/log/nginx/gitlab_access.log; 
    error_log /var/log/nginx/gitlab_error.log; 

    location/{ 
     # serve static files from defined root folder;. 
     # @gitlab is a named location for the upstream fallback, see below 
     try_files $uri $uri/index.html $uri.html @gitlab; 
    } 

    # if a file, which is not found in the root folder is requested, 
    # then the proxy pass the request to the upsteam (gitlab unicorn) 
    location @gitlab { 
     proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694 
     proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694 
     proxy_redirect  off; 

     proxy_set_header X-Forwarded-Proto $scheme; 
     proxy_set_header Host    $http_host; 
     proxy_set_header X-Real-IP   $remote_addr; 

     proxy_pass http://gitlab; 
    } 
} 

注意:我訪問它有它的條目同一本地網絡上從OSX機器上的兩個域的/etc/hosts文件像這樣:

192.168.1.100 db.mydomain.com 
192.168.1.100 git.mydomain.com 
+1

簡單的解釋是,如此這般的第一個服務器的請求不符合任何'server_name'除非有一個定義作爲'default_server' –

+0

確實'http://git.mydomain.com:90'能正常工作嗎? –

+0

@MohammadAbuShady看起來你是對的。由於某些原因,「server_name」都不匹配,所以它只是按字母順序選擇第一臺服務器。任何想法如何我可以告訴'server_name' nginx看到了什麼? –

回答

0

嘗試使用:

server_name git.mydomain.com:90; 

...和:

server_name db.mydomain.com:90;