2016-01-16 20 views
1

好吧,我有一臺我公司用於Web服務器的虛擬機。我們有一個內部的PHP應用程序,現在需要添加一個站點到這個服務器。問題是VM上有一個IP。我將Windows DNS Manger設置爲指向此IP,但它只會拉起主站點。有沒有一種方法可以將nginx配置到將選擇要提取哪個站點的位置?NGINX Mulitple Site Config One IP

這是我第一次現場配置:

server { 

    server_name develop.aspirion.com; 


    root /var/www/vhosts/develop.aspirion.com; 
    index index.html; 

    location ~ \.php$ { 

    try_files $uri =404; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    fastcgi_pass unix:/var/run/php5-fpm/php5-fpm.sock; 
    fastcgi_index index.php; 
    include fastcgi_params; 
} 
} 

這裏是我的第二個網站的配置:

server { 

server_name aspirion.com; 

access_log /var/log/nginx/aspirion.com-access.log; 
error_log /var/log/nginx/aspirion.com-error.log; 

root /var/virtual/aspirion.com/master/current/webroot; 
index index.php; 

location/{ 
    # error_page 404 /index.php; 

    location =/{ 
    error_page 404 =200 /index.html; 
    } 

    location ~* ^.+\.(?:css|js|jpe?g|gif|htc|ico|png|html|xml)$ { 
    access_log off; 
    expires 30d; 
    tcp_nodelay off; 
    open_file_cache max=3000 inactive=120s; 
    open_file_cache_valid 45s; 
    open_file_cache_min_uses 2; 
    open_file_cache_errors off; 
    } 
    location ~* ^.+\.(?:pdf|pptx?)$ { 
    expires 30d; 
    tcp_nodelay off; 
    } 

    # TODO: never allow private files inside the web root? 
    location ^~ /sites/default/files/private/ { 
    internal; 
    } 

    location ~* ^(?:.+\.(?:htaccess|make|txt|engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(?:\.php)?|xtmpl)|code-style\.pl|/Entries.*|/Repository|/Root|/Tag|/Template)$ { 
    return 404; 
    } 

    try_files $uri $uri/ /index.php?$uri&$args; 
} 

location = /index.php { 
    fastcgi_pass phpcgi; 
} 

location = /.git { 
    return 404; 
} 

location = /patches { 
    return 404; 
} 

location = /backup { 
    return 404; 
} 

location = /robots.txt { 
    access_log off; 
} 

location = /humans.txt { 
    access_log off; 
    try_files $uri $uri/ /index.php?$uri&$args; 
} 

location = /rss.xml { 
    try_files $uri $uri/ /index.php?$uri&$args; 
} 

location = /sitemap.xml { 
    try_files $uri $uri/ /index.php?$uri&$args; 
} 

location = /favicon.ico { 
    try_files /favicon.ico =204; 
} 

location ~* ^.+\.php$ { 
    return 404; 
} 
} 

server { 
server_name munin.aspirion.com; 

include sites-available/admin.conf; 
} 

回答

1

是的,這是正常的Nginx從單個IP地址用於多個領域。

瀏覽器將兩個域的DNS解析爲相同的IP,然後將該通信轉發到該IP地址上的端口80。 Nginx正在監聽並檢查傳入的Host:標題,並將其與您配置中的server_name值進行匹配。您的問題與一個IP地址上有兩個域無關。試試這個東西:

  1. 更改Nginx配置文件後,請確保重新加載Nginx。
  2. 確保所有域都實際啓用。 (即:如果你把文件放入sites-available,確保有符號鏈接到sites-enabled
  3. 嘗試更簡單的配置,嘗試只配置一個域的配置,然後嘗試只配置其他域的配置。 。提供簡單的靜態文件
  4. 檢查DNS要涉及所有域應最終解決到虛擬機的IP檢查每一個:。dig +short example.com
  5. 嘗試更改配置出現在Nginx的配置文件中的順序這不應該申請,因爲我沒有看到通配符匹配,但如果沒有別的工作...

您的Nginx配置顯示您有單獨的server塊,具有唯一的server_name值,因此通常您的配置在單個IP地址上託管多個域時看起來不錯。 (如果你碰巧已經刪除了SSL配置,可能有相關的問題,但我假設不是基於你的配置)。