Apache-2.2

通過 httpd.conf 從 Staging Server 的子域中刪除 WWW

  • November 28, 2011

我正在嘗試設置一個登台伺服器作為我的生產伺服器的子域執行,但我遇到了一個小問題。

我的生產伺服器託管在 RackSpace 虛擬機上。我複製了這台機器用作我的登台伺服器。我還添加了A記錄以將子域地址定向到這個新虛擬機。

我希望能夠通過鍵入來訪問這個登台伺服器staging.domain.com,但目前這不起作用。我發現有效的解決方法是鍵入www.staging.domain.com. www注意子域前面的額外內容。

我的目錄結構是這樣的,在我的項目目錄中,我有一個public_html目錄(顯然包含可公開查看的文件)和一個private(包含更多後端程式碼)。/var/www/staging.domain.com/public_html/index.php當我訪問staging.domain.com.

如前所述,我目前只能通過訪問來獲得我想要的東西www.staging.domain.com。當我訪問staging.domain.com時,我被重定向到www.staging.domain.com/staging.domain.com/public_html.

我的 httpd.conf 設置如下(我絕對不是這個文件的配置專家):

<VirtualHost *:80>
   # General Server Setup
   ServerAdmin admin@domain.com
   ServerName  www.staging.domain.com
   ServerAlias staging.domain.com

   # Indexes + Directory Root
   DirectoryIndex index.php index.html
   DocumentRoot /var/www/staging.domain.com/public_html
   <Directory /var/www/staging.domain.com/public_html>
           Options Indexes FollowSymLinks MultiViews
           AllowOverride All
           Order allow,deny
           Allow from all
   </Directory>
</VirtualHost>

```




I am pretty sure that the redirect I spoke of earlier is happening because of my specified `DocumentRoot` in this file.


Also, I have tried many different combinations of `CNAME` and `A` records trying to get this to work, but I'm open to any other suggestions you might have.


### Update


I don't have anything specified for my `.htaccess` file, so that shouldn't be effecting anything. 


My current DNS record for this server are:



```
**Type Name Content TTL**
A       staging.domain.com        XX.XX.XX.XX(server IP)    300
A       www.staging.domain.com    XX.XX.XX.XX(server IP)    300

```

There is really no additional information that I've configured that I can think of to share with you. If you can think of anything just ask.`

It turns out that there was a default .htaccessfile in the/var/www/ directory that was causing this action. I removed it as suggested by @Shane_Madden which fixed the problem.

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