Apache虛擬機器主機的搭建及相關問題解決

來源:互聯網
上載者:User

標籤:cal   http   default   127.0.0.1   設定檔   efault   就會   server   搭建   

在開發的過程中,很多時候項目的部署都需要在本地進行虛擬伺服器的類比搭建,所以具體的配置流程為下,並且把自己遇到的問題跟大家分享。

1、Apache設定檔httpd.conf

   找到
   # Virtual hosts 這句前面的#不用去 //如果去掉了,你就會發現localhost和你設定的網域名稱路徑都會訪問不了項目!!
   #Include conf/extra/httpd-vhosts.conf 去掉本行注釋 #  //這個是一定一定要去掉的!!!

  還有 severname localhost  前面需要加#,注釋掉。

2、Apache檔案目錄

    apache/conf/extra/http-vhosts.conf
  
   複製添加如下代碼到該檔案的最後面。
  
 

當我們配置完網域名稱訪問到項目的時候經常會出現localhost訪問不了的問題,這時候就需要加下面這部分代碼了!!

<VirtualHost _default_:80>
DocumentRoot "D:/phpStudy2/WWW"   //指向正確的www檔案
ServerName localhost   //保證localhost也可以訪問
</VirtualHost>

//下面的這部分代碼是非常重要的!!就是正確佈建網域名的部分

<VirtualHost *:80>
  DocumentRoot "D:/phpStudy2/WWW/tpshop"   //指向正確的項目位置
  ServerName www.leohc.com                                //對應的網域名稱設定
  DirectoryIndex index.html index.htm index.php
  <Directory />
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
  </Directory>
</VirtualHost>



3、 找到hosts檔案

    C:\Windows\System32\drivers\etc\hosts
    
    在最後添加如下

  127.0.0.1      localhost 
    127.0.0.1      www.leoyi.com #設定本地訪問網址 (與上ServerName一致)


 最後重啟Apache伺服器

 

  兩個燈都顯示為綠色就說明是正常的。
  

Apache虛擬機器主機的搭建及相關問題解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.