2014-05-21 94 views
5

我在我的Ubuntu 14.04機器上安裝了Apache 2.4.7,並且我的一些虛擬主機不同意我的觀點。我有5個虛擬主機,我嘗試運行;其中3人工作,2人不工作。兩個不工作的conf文件是:Ubuntu 14.04:Apache 2.4.7虛擬主機不工作/重定向

002-tmpnet.conf

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot /var/www/html/tmpnet 
    ServerName tmpnet 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride All 
    </Directory> 
    <Directory /var/www/html/tmpnet/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride All 
     #Order allow,deny 
     #allow from all 
     Require all granted 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
    CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

003 tmpcom.conf

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    DocumentRoot /var/www/html/tmpcom 
    ServerName tmpcom 
    <Directory /> 
     Options FollowSymLinks 
     AllowOverride All 
    </Directory> 
    <Directory /var/www/html/tmpcom> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride All 
     #Order allow,deny 
     #allow from all 
     Require all granted 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 
     CustomLog ${APACHE_LOG_DIR}/access.log combined 
</VirtualHost> 

這兩個返回

500 Internal server errors 

whe ñ試圖訪問他們。如果我通過本地主機(即localhost/html/tmpnet)訪問它們,它可以很好地工作,而不是在嘗試使用虛擬主機時。

hosts文件是:

127.0.0.1 localhost 
127.0.1.1 Eagle 
127.0.1.1 tmpcom 
127.0.1.1 tmpbiz 
127.0.1.1 tmporg 
127.0.1.1 tmpnet 
127.0.1.1 thatsmybrick 

# The following lines are desirable for IPv6 capable hosts 
::1  ip6-localhost ip6-loopback 
fe00::0 ip6-localnet 
ff00::0 ip6-mcastprefix 
ff02::1 ip6-allnodes 
ff02::2 ip6-allrouters 

和我apache2.conf是:

Mutex file:${APACHE_LOCK_DIR} default 
PidFile ${APACHE_PID_FILE} 
Timeout 300 
KeepAlive On 
MaxKeepAliveRequests 100 
KeepAliveTimeout 5 

# These need to be set in /etc/apache2/envvars 
User ${APACHE_RUN_USER} 
Group ${APACHE_RUN_GROUP} 

HostnameLookups on 
ErrorLog ${APACHE_LOG_DIR}/error.log 
LogLevel warn 
IncludeOptional mods-enabled/*.load 
IncludeOptional mods-enabled/*.conf 
Include ports.conf 

<Directory /> 
    Options FollowSymLinks 
    AllowOverride All 
    Require all denied 
</Directory> 

<Directory /usr/share> 
    AllowOverride All 
    Require all granted 
</Directory> 

<Directory /var/www/> 
    Options Indexes FollowSymLinks 
    AllowOverride All 
    Require all granted 
</Directory> 

AccessFileName .htaccess 

<FilesMatch "^\.ht"> 
    Require all denied 
</FilesMatch> 

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined 
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined 
LogFormat "%h %l %u %t \"%r\" %>s %O" common 
LogFormat "%{Referer}i -> %U" referer 
LogFormat "%{User-agent}i" agent 

IncludeOptional conf-enabled/*.conf 

IncludeOptional sites-enabled/*.conf 

我一直停留在這很長一段時間了,我真的會感謝一些幫助。任何指向正確的方向將是驚人的。

謝謝

回答

1

你還在面臨的問題?

你看了一下位於/var/log/apache2/error.log的錯誤日誌。錯誤日誌是不言自明的,並且會給出問題的良好結果。

我的機器上的誤差表明這一點(錯誤語句的後半部分)

的.htaccess:無效命令「RewriteEngine敘述」,也許拼錯或 由模塊定義爲不包括在所述服務器配置

在我的情況下,Apache模塊重寫未啓用。我啓用了該模塊,並且虛擬主機設置還活着。

另外我看到你正在使用語句'AllowOverride All',它表示你正在嘗試使用重寫模塊。使用命令sudo a2enmod rewrite啓用模塊「重寫」,然後重新啓動apache2 sudo /etc/init.d/apache2 restart

看看這是否有幫助!

7

這可能有點晚,不知道你是否找到了解決方案,但這就是我所做的。花了好幾個小時修改我的配置文件並調整我的虛擬主機後,我決定使用a2dissite 000 ...默認網站並重新加載apache。一旦我做到了,重定向就像epxected一樣工作。我不知道當你在服務器上有多個站點時它會如何展開,如果它默認爲第一個加載的虛擬主機,或者......我總是覺得apache必須有一個默認主機,我可以這是錯誤的。

+0

謝謝!!!我運行了'a2dissite 000-default.conf'並將'.conf'添加到我現有的文件中,並且它工作正常! – Skovy

4

我正面臨這個問題,事實證明,我不得不禁用默認的虛擬主機。

sudo a2dissite 000-default.conf 
-1

好了,問題是這樣的:

IncludeOptional sites-enabled/*.conf

這意味着它會包括文件名末尾帶.conf虛擬主機文件。

重命名它們或更改指令。

的Ciao, Gelma

+0

我不認爲你讀過這個問題。他的文件**被**命名爲'.conf',但仍未加載。 – Machavity

0

如果你是從精確的(12.04)進行升級,那麼你需要的.conf擴展添加到您的虛擬主機配置文件

例如,以前你有這樣的配置

/etc/apache2/sites-available/project 

,那麼你需要的.conf擴展添加到它,

/etc/apache2/sites-available/project.conf 

,當然你必須創建中啓用了站點文件夾一個新的符號鏈接,CD以啓用站點文件夾和

sudo ln -s ../sites-available/project.conf 

重啓Apache就大功告成了。

5

我不僅要禁用默認:

sudo a2dissite 000-default.conf 

,但我也不得不重裝Apache作爲sudo的 - 沒有sudo它沒有重裝正確

sudo service apache2 reload 
+1

重新裝載期間SUDO完成了它的工作!謝謝 :) –