2015-04-16 77 views
2

我剛開始學習PHP,我試圖通過使用XAMPP在本地託管我自己的PHP網站。阿帕奇虛擬主機404找不到

我想創造的虛擬主機有:

網址:myphpwebsite.local

端口:8088

但是,當我試圖通過瀏覽器訪問這個網站我有一個:

未找到 HTTP錯誤404。未找到請求的資源。

有誰知道這個問題是什麼?

我的httpd-vhosts.conf

NameVirtualHost 127.0.0.1:8088 
<VirtualHost 127.0.0.1:8088> 
    DocumentRoot "C:/xampp/htdocs" 
    ServerName localhost 
</VirtualHost> 

<VirtualHost myphpwebsite.local> 
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite" 
    ServerName myphpwebsite.local 
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log" 
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined 

    <Directory "C:/Microsoft/Workspace/myphpwebsite"> 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 

而我的C:\ WINDOWS \ SYSTEM32 \ DRIVERS \ ETC \ hosts文件:

127.0.0.1  localhost 
127.0.0.1 myphpwebsite.local 

任何幫助,將不勝感激!

回答

0

NameVirtualHost指令需要完全匹配VirtualHost的值,並且您需要在每個實例中指定端口。如果你想使用端口8088進行myphpwebsite.local,你需要做的:

NameVirtualHost 127.0.0.1:8088 
<VirtualHost 127.0.0.1:8088> 
    DocumentRoot "C:/xampp/htdocs" 
    ServerName localhost 
</VirtualHost> 

<VirtualHost 127.0.0.1:8088> 
    DocumentRoot "C:/Microsoft/Workspace/myphpwebsite" 
    ServerName myphpwebsite.local 
    ErrorLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.error.log" 
    CustomLog "C:/Microsoft/Workspace/myphpwebsite/logs/myphpwebsite.local.custom.log" combined 

    <Directory "C:/Microsoft/Workspace/myphpwebsite"> 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 

通知之VirtualHost開始標籤是相同的;這是ServerName值,它實際上告訴Apache此特定指令適用於哪個域。進行更改後重新啓動服務器。看看這個頁面的更多信息:http://httpd.apache.org/docs/2.2/vhosts/name-based.html

希望這有助於!

+0

@Avil如果這仍然不起作用,確保你的'DocumentRoot'的文件夾確實存在,'Listen 8088'在你的httpd.conf中。我犯了更嚴重的錯誤。 :) –

1

我不知道我是否有很多幫助,但使用WAMP,這裏是我的設置。我在端口80上偵聽,我使用8080作爲我的tomcat服務器。

hosts文件

127.0.0.1 local.mysite.com 

的httpd-vhosts.conf

# 
# Use name-based virtual hosting. 
# 
NameVirtualHost *:80 

.... 

<Directory "c:/wamp/www"> 
    Options Indexes MultiViews FollowSymLinks 
    Order Deny,Allow 
    Deny from all 
    Allow from 127.0.0.1 
</Directory> 
<VirtualHost *:80> 
    ServerName localhost 
    DocumentRoot "c:/wamp/www" 
</VirtualHost> 

<Directory "c:/wamp/www/path/to/site/root"> 
    Options Indexes MultiViews FollowSymLinks 
    AllowOverride None 
    Order allow,deny 
    Allow from all 
</Directory> 
<VirtualHost *:80> 
    ServerName local.mysite.com 
    DocumentRoot "c:/wamp/www/path/to/site/root" 

    ServerAdmin [email protected] 

    ProxyPreserveHost Off 
    RewriteEngine On 
    AllowEncodedSlashes NoDecode 
    #AllowEncodedSlashes On 

    ErrorLog "c:/wamp/www/path/to/logs/error.log" 
    CustomLog "c:/wamp/www/path/to/logs/access.log" common 
</VirtualHost> 

.... 

然後,我可以訪問我的本地站點是這樣的:http://local.mysite.com

希望這有助於...

0
  1. 確保有任何目錄要打開文件/ htaccess的/指數或404可以來自於)

  2. 嘗試下面用一個,最終取代你的端口:

    <VirtualHost *:80> 
        DocumentRoot "C:/Microsoft/Workspace/myphpwebsite" 
        ServerName myphpwebsite.local 
        </VirtualHost> 
    
  3. 問題是你的Apache在8088端口上運行/服務? 例如我的xamp在80和443上運行...

  4. xamp控制面板非常方便,它有很好的日誌按鈕,將打開您的日誌文件,以顯示您的PHP和Apache錯誤等檢查出來。

嘗試使用默認端口,如果它的工作,這意味着如果你真的想要,你需要與端口一起玩。

只是一個快速提示,.com比.local短,如果您使用的是Chrome瀏覽器,並且它的工作方式與我的一樣,那麼大多數情況下,something.local會將您重定向到Google搜索(並且我喜歡我的搜索,你可以把它關掉;))