哎!也真是倒霉啊,就在快将虚拟主机配置好的时候出现了这么一件事情就是,误执行了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了