CentOS 7 的httpd VirtualHost 該如何設定 - Linux

Table of Contents

這幾天使用CentOS 7 安裝一個網站,檔案放在/var/www/html/aaaa
跑起來很正常(此時用 htt p://IP/aaaa/ 連上)
但是在我使用VirtualHost處理後卻一直出現400 bad request

負責連上去的主機在/etc/hosts增加
192.168.0.213 aaaa.test.tw
192.168.0.213 aaaa_bbbb.test.tw

伺服器這邊
localhost的DN是 aaaa.test.tw,指到/var/www/html
VirtualHost的DN是 aaaa_bbbb.test.tw,指到/var/www/bbbb
(預期還要增加cccc dddd eeee....)

狀況以alias過的phpmyadmin來說

htt p://192.168.0.213/phpmyadmin 正常
htt p://aaaa.test.tw/phpmyadmin 正常
htt p://aaaa_bbbb.test.tw/phpmyadmin 400 bad request

因為資料夾在mv之前網站是可以正常運作的,因此應該不是權限的問題

LOG的部份有寫到指定的檔案中,因此設定檔是有被讀進去的
測試一直失敗於是一直調設定檔重開服務
有時localhost的紀錄寫到VirtualHost那邊
有時VirtualHost的紀錄寫到localhost去
不變的是只要連到aaaa_bbbb.test.tw就會400 bad request

還請有經驗的人指導一下orz

VirtualHost.conf的設定

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/bbbb
ServerName "aaaa_bbbb.test.tw"
#ServerName aaaa.test.tw
#ServerAlias aaaa_bbbb.test.tw
CustomLog logs/bbbb_access.log combined
ErrorLog logs/bbbb_error.log
LogLevel warn
<Directory "/var/www/bbbb">
DirectoryIndex index.html index.php
Options MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>


httpd.conf一開始沒有動,因為測試一直沒成功也改了一堆,
這裡貼的是一開始的狀態


ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost

<Directory />
AllowOverride none
Require all denied
</Directory>

DocumentRoot "/var/www/html"

<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

<IfModule dir_module>
DirectoryIndex index.html
</IfModule>

<Files ".ht*">
Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
\"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>

<IfModule mime_module>
TypesConfig /etc/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
MIMEMagicFile conf/magic
</IfModule>

#EnableMMAP off
EnableSendfile on
IncludeOptional conf.d/*.conf



--
~hc是個有美女就好的軟派阿宅,各種被大家批評的作品他都有辦法看的津津有味~
路人:BLEACH超好看的 hc:不斷創造出神入化視效大決,久保老師總是能讓讀者驚奇。
路人:火影忍者超好看的 hc:用BL映襯女性的幽怨哀愁,岸本老師編劇有如神之一手。
路人:網球王子超好看的 hc:持續挑戰自我與人類的極限,許斐老師重新定義進化一詞。
路人:卡通柯南超好看的 hc:案件後藏著綿密的愛恨情仇,青山老師何時挑戰言情小說?
路人:艦娘動畫超好看的 hc:....他喵的你當我潘子嗎?

--

All Comments

Charlie avatarCharlie2018-08-02
SElinux有開嗎?有開有可能是它在搞鬼,用ls -Z看一下你
/var/www/aaa跟bbb的context有沒有相同
Ina avatarIna2018-08-04
SElinux已經關了
Zenobia avatarZenobia2018-08-04
如果把bbbb移到/var/www/html/下面,只要VirtualHost
Kyle avatarKyle2018-08-08
的設定上去,會連/var/www/html/底下的東西都連不上
因此VirtualHost的設定是有作用但是不知道有什麼問題
Anthony avatarAnthony2018-08-08
....原因找到了,Domain Name 不能用 _ ,拿掉就正常
Oliver avatarOliver2018-08-12
不是CentOS7或apache的問題,是我自己豬頭orz