哎!也真是倒黴啊,就在快将虛拟主機配置好的時候出現了這麼一件事情就是,誤執行了iptables -F,我的伺服器iptables是已經配置好的,如果預設政策已經配置為deny的話,再使用iptables -F,會導緻網絡立馬中斷!然後瞬間我的xshell就斷開連接配接,再去連接配接已經連接配接不上了。我是将我的伺服器重新開機之後,再連接配接就行了,這個時候apache沒有啟動,執行一下systemctl restart httpd.service。然後執行systemctl status httpd.service -l檢視是否成功開啟,顯示如下資訊則說明開啟了
我的apache不知道在安裝的時候發生了什麼問題,每次用xshell連接配接後,都需要重新開機一下apache,然後設定Apache系統引導時啟動:echo “/usr/local/apache2/bin/apachectl start” >> /etc/rc.d/rc.local檢視是否寫入成功:tail /etc/rc.local
下面進入主題就是配置虛拟主機:
安裝完成LAMP環境之後,下邊就開始配置虛拟主機了。我個人建議的是,用一個單獨的檔案專門用來放置自己的虛拟主機:我這裡命名為vhost.conf
#vim /etc/httpd/conf.d/vhost.conf
添加到該檔案下的内容如下:
#虛拟主機配置檔案
<VirtualHost 公網IP:>
#綁定的主域
ServerName shulv.com
#綁定的子域名
ServerAlias www.shuvl.com
#網站主目錄
DocumentRoot /var/www/html/www.shulv.com/
#日志路徑配置(如果沒有,請記得建立)
ErrorLog /var/www/html/web_log/error_shulv.com.log
CustomLog /var/www/html/web_log/custom_shulv.com.log common
#ServerSignature Off
</VirtualHost>
#網站的配置
<Directory "/var/www/html/www.shulv.com/">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
下邊是建立你可能沒有建立的檔案:
#mkdir /var/www/www.bookstore.com
#mkdir /var/www/web_log
#service httpd restart<span style="white-space:pre"> </span>重新開機Apache
//如果重新開機中碰到了報錯,比如:caught SIGWINCH, shutt ing down gracefully。
//一般是文法問題,導緻Apache無法啟動成功,可以使用如下目錄檢視啟動失敗原因:
#systemctl status httpd.service -l 或者journalctl -xe
//搞定了上面之後,可以試試php腳本能不能運作:
#vim /var/www/www.bookstore.com/index.php
添加測試代碼:
<?php phpinfo();?>
那麼重新開機一下你的apache就OK了