簡體   English   中英

Apache 2, ubuntu - VHost 不工作

[英]Apache 2, ubuntu - VHost doesn't work

我想在我的機器上創建 VHost。

我的配置:

/etc/hosts

127.0.0.1 mysite.dev

/etc/apache2/sites-available/mysite.dev

<VirtualHost *:80>
    SetEnv APPLICATION_ENV "development"
    ServerName mysite.dev
    DocumentRoot /home/michal/Public/mysite/public/frontend

    <Directory /home/michal/Public/mysite/public/frontend>
        Options Indexes FollowSymLinks Includes
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

我跑后

sudo a2ensite mysite.dev
sudo /etc/init.d/apache2 restart

現在,當我在瀏覽器中輸入 mysite.dev 時,我會看到標准的 Apache index.html(“它有效!”)。 為什么? 我應該在哪里找到我的問題?

從您的問題中不太清楚您要實現的目標。 如果要轉發到特定的URL,請說HTTPS URL,那么可以使用以下幾行來實現:

  <VirtualHost *:80>
     ServerName localhost:80
     RedirectMatch permanent ^(.*)$ https://localhost:8443$1
</VirtualHost>

如果您嘗試配置apache服務器,jboss服務器和mod_jk,則可以參考此鏈接

好,這是一年前提出的,但今天我遇到了同樣的問題,也許我發現的解決方案對其他人會很有幫助,所以就在這里。

對我有用的是重命名/ etc / apache2 / sites-enabled中的軟鏈接,將擴展名.conf附加到該文件夾​​中的每個鏈接。

因此,如果我們具有以下鏈接:

/etc/apache2/sites-enabled$ ls -l
lrwxrwxrwx 1 root root 23 Nov 30  2012 site1 -> ../sites-available/site1   
lrwxrwxrwx 1 root root 23 Nov 30  2012 site2 -> ../sites-available/site2

我們應該同時將其重命名為site1.conf和site2.conf

/etc/apache2/sites-enabled$ sudo mv site1 site1.conf
/etc/apache2/sites-enabled$ sudo mv site2 site2.conf

然后,當然,重新啟動apache

/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart

之所以如此,是因為Apache在最近一段時間更改了該文件的命名方式,以便正確加載它們,如apache2.conf文件的最后幾行所述。

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

禁用默認的 Apache 虛擬主機

sudo a2dissite 000-default.conf

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM