Apache-2.2

如何將同一域指向 Apache 中的單個應用程序

  • July 16, 2013

我的 webroot 中有兩個應用程序,

/var/www/mysite
/var/www/blog

我想訪問mysite應用程序http://mysite.com,類似地訪問部落格 應用程序http://mysite.com/blog. 我正在本地嘗試這個設置,所以我已經更新了主機文件,如下行。

 127.0.0.1 mysite.com www.mysite.com    
 127.0.0.1 mysite.com/blog www.mysite.com/blog # May be looks somewhat foolish with this line

我已經為mysite應用程序創建了一個虛擬主機DocumentRoot/var/www/mysite並且能夠訪問它,但我無法理解是否需要為部落格應用程序創建單獨的虛擬主機,或者我需要修改現有的mysite虛擬主機文件?

以下是mysite應用程序虛擬主機文件,

<VirtualHost *:80>
     ServerAdmin webmaster@localhost
     ServerName www.mysite.com
     ServerAlias myssite.com

   RewriteEngine On
   RewriteCond %{HTTP_HOST} !^www\. [NC]
   RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [R=301,L]

   DocumentRoot /var/www/mysite
   <Directory />
      Options None
      Order deny,allow
      allow from all
   </Directory>
  <Directory /var/www/mysite>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
  </Directory>

   SetEnvIf Host (.*) custom_host=$1
   <Directory "/usr/lib/cgi-bin">
       AllowOverride None
       Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
       Order allow,deny
       Allow from all
   </Directory>

   ErrorLog /var/log/apache2/error-mysite.log

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

   CustomLog /var/log/apache2/access-mysite.log combined

   Alias /doc/ "/usr/share/doc/"
   <Directory "/usr/share/doc/">
       Options Indexes MultiViews FollowSymLinks
       AllowOverride None
       Order deny,allow
       Deny from all
       Allow from 127.0.0.0/255.0.0.0 ::1/128
   </Directory> 
</VirtualHost>

恕我直言,部落格不需要單獨的 virt 主機。您只需要使用別名

<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   ServerName www.mysite.com
   ServerAlias myssite.com

   DocumentRoot /var/www/mysite
   Alias /blog /var/www/blog

  <Directory /var/www/mysite>
     Options Indexes FollowSymLinks MultiViews
     AllowOverride All
     Order allow,deny
     allow from all
  </Directory>

  <Directory /var/www/blog>
     ...
  </Directory>
</VirtualHost>

引用自:https://serverfault.com/questions/523638