CentOS7 在conf.d新增VirtualHost後無法啓動httpd
-
好多人在新setup 的CentOS7, 新增VirutalHost後, 無法啓動Apache. 原因是使用了網上流傳的這段:
<VirtualHost *:80> ServerName www.yourdomain.com ServerAlias yourdomain.com DocumentRoot /var/www/yourdomain.com/public_html ErrorLog /var/www/yourdomain.com/error.log CustomLog /var/www/yourdomain.com/requests.log combined </VirtualHost>
而其實在新版的CentOS7.1以後, 要用下面這段才可以
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com ServerAdmin [email protected] DocumentRoot /var/www/example.com/public_html <Directory /var/www/example.com/public_html> Options -Indexes +FollowSymLinks AllowOverride All </Directory> ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined </VirtualHost>
放進etc/httpd/conf.d 內, 以xxxxx.conf 命名就可以
沒需要另外開一個新folder allowsite然後,
systemctl restart httpd最後開防火牆
firewall-cmd –permanent –zone=public –add-service=http
firewall-cmd –reload
iptables -A INPUT -p tcp -m tcp –dport 80 -j ACCEPT
/etc/init.d/iptables save