2012-09-13 98 views
0

我正在嘗試做什麼:將站點(mydomain.com)添加到apache2/sites-available(我已指定其文檔根目錄),然後啓用它並在此之後在我的本地機器上訪問它(如瀏覽器中的mydomain.com)。我有一些以下查詢:virtualhost-mydomain.com在本地機器

  1. 是否有可能創建一個網站,並給它一個特定的域名(mydomain.com)?
  2. 我需要遵循什麼步驟來創建一個站點>給一個域>只在本地機器上訪問它。

備註:我有網站的內容。我想創建一個新網站,我不想更改apache的默認網站(即apache2/sites-available/default)。

UPDATE:

我面臨在重新啓動Apache的一個錯誤(如描述我已經添加虛擬主機)

ERROR

CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" clause (see docs) 
Action 'configtest' failed. 
The Apache error log may have more information. 
    ...fail! 

我的網站的文件

<VirtualHost *:80> 

     ServerAdmin [email protected] 
     ServerName dev.subhransu.com 

     ScriptAlias /private /home/hg/repositories/private/hgweb.cgi 
     <Directory /home/hg/repositories/private/> 
       Options ExecCGI FollowSymlinks 
       AddHandler cgi-script .cgi 
       DirectoryIndex hgweb.cgi 
       AuthType Basic 
       AuthName "Mercurial repositories" 
       AuthUserFile /home/hg/tools/hgusers 
       Require valid-user 
     </Directory> 

     ErrorLog ${APACHE_LOG_DIR}/dev.subhransu.com_error.log 

     # Possible values include: debug, info, notice, warn, error, cr$ 
     # alert, emerg. 
     LogLevel warn 

     CustomLog ${APACHE_LOG_DIR}/dev.subhransu.com_ssl_access.lo$ 

     SSLEngine on 
     SSLCertificateFile "/etc/apache2/ssl/dev.subhransu.com.crt" 
     SSLCertificateKeyFile "/etc/apache2/ssl/dev.subhransu.com.k$ 

</VirtualHost> 

httpd.conf文件文件

<VirtualHost *:80> 
ServerName dev.subhransu.com 
ServerAlias www.dev.subhransu.com 
</VirtualHost> 
在httpd.conf
+0

你有你的CustomLog指令第二個參數?您虛擬主機中的信息被截斷,所以我無法告訴您在CustomLog指令結束時放置了什麼。下面是一個CustomLog指令的例子:'CustomLog'/path/to/log/file/logs/access.log「combined」 –

回答

1

(或虛擬主機),在服務器名和serveralias設置是什麼域名Apache將到

ServerName mydomain.com 
ServerAlias www.mydomain.com 

迴應則只需編輯您的主機文件指向mydomain.com到127.0.0.1

1

我認爲你可能要找的功能是虛擬主機。藉助虛擬主機,您可以創建任意數量的站點,每個站點獨立於另一個站點。對於每個虛擬主機,你可以指定「ServerName」指令,它是你的域名,它可以是你想要的任何東西。然後在您的計算機主機文件中,您可以將該域的所有呼叫路由到本地主機。

如果您只有一個需要設置的站點,請編輯默認的apache配置,單獨保留vhost,然後像我之前提到的那樣更新您計算機上的hosts文件。

參考文獻: vhost examples How to edit your hosts file