2013-04-12 35 views
1

我有一個Ubuntu的機器,它有一個ip地址綁定到它,我有一個網站,我想配置在我的虛擬主機。問題是如果我沒有指向它的域,我應該在我的server_name中放置什麼?基本上我想這樣當我輸入我的IP地址2xx.xxx.xxx.xxx然後它去這個網站。這裏是我當前的配置配置nginx server_name如果你沒有任何域名指向它

server { 
     listen   80; 
     server_name  dev.somesite.com; 
     client_max_body_size 25M; 
     access_log  /var/log/nginx/dev.somesite.com.access_log; 
     error_log  /var/log/nginx/dev.somesite.com.error_log warn; 
server_name_in_redirect off; 
     root   /var/www/somesite-dev/web; 
     location/{ 
       try_files $uri /app_dev.php?$args; 
     } 
     index   app_dev.php index.php index.html; 
     fastcgi_index index.php; 

     location ~ \.php($|/) { 
       set $script $uri; 
       set $path_info ""; 

       if ($uri ~ "^(.+\.php)(/.*)") { 
         set $script  $1; 
         set $path_info $2; 
       } 
       fastcgi_split_path_info ^(.+\.php)(/.+)$; 
       fastcgi_param PATH_INFO $fastcgi_path_info; 
       fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; 
       include /etc/nginx/fastcgi_params; 
       keepalive_timeout 0; 
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
       fastcgi_pass 127.0.0.1:9000; 
     } 
    } 

回答

3

Server_name用於基於名稱的虛擬主機,如果您不需要,可以將其全部保留。它會聽IP很好。請記住,如果您有多臺不使用基於名稱的解決方案的服務器,則會導致問題,您將只能訪問其中的一臺。哪一個取決於兩件事情:

  1. 如果你有「聽80默認」中的一臺服務器,該服務器將優先考慮
  2. 如果沒有上述情況,其配置的服務器讀取首先會處理請求
1

您應該設置服務器名至如development.local,然後在您將development.local指向您的服務器的IP或本地主機時,向您的/ etc/hosts文件中添加一行。