安装apache
启动apache
1
|
$ systemctl start httpd.service
|
查看是否开启成功
1
2
3
4
5
6
7
8
|
[root@centos7-1 ~] $ ps -ef|grep httpd
root 1739 1 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1740 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1741 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1742 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1743 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 1744 1739 0 18:34 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
root 1749 1112 0 18:37 pts/0 00:00:00 grep --color=auto httpd
|
查看apache端口
1
|
$ netstat -lntup|grep httpd
|
修改hosts解析
改成如下内容
1
|
192.168.56.101 centos7.com www.centos7.com bbs.centos7.com blog.centos7.com
|
测试访问
1
|
$ curl www.centos7-1.com
|
配置apache
备份文件
1
|
$ cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.back
|
配置httpd文件
因为在apache2.4中变化挺大,和nginx一样,可以自定义.conf文件。
在主配置文件中启用虚拟主机
1
2
3
|
$ mkdir /etc/httpd/vhost.d/
$ echo "include vhost.d/*.conf"
$ tail -1 /etc/httpd/conf/httpd.conf
|
配置多站点目录
1
|
$ vi /etc/httpd/vhost.d/name.conf
|
写入下面的内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
<VirtualHost *:80>
ServerAdmin admin@amsilence.com
DocumentRoot "/var/html/www"
ServerName www.centos7.com
ErrorLog "/var/httpd/logs/www-error_log"
CustomLog "/var/httpd/logs/www-access_log" common
</VirtualHost>
<Directory /var/html/www/>
Require all granted
</Directory>
<VirtualHost *:80>
ServerAdmin admin@amsilence.com
DocumentRoot "/var/html/bbs"
ServerName bbs.centos7.com
ErrorLog "/var/httpd/logs/bbs-error_log"
CustomLog "/var/httpd/logs/bbs-access_log" common
</VirtualHost>
<Directory /var/html/bbs/>
Require all granted
</Directory>
<VirtualHost *:80>
ServerAdmin admin@amsilence.com
DocumentRoot "/var/html/blog"
ServerName blog.centos7.com
ErrorLog "/var/httpd/logs/blog-error_log"
CustomLog "/var/httpd/logs/blog-access_log" common
</VirtualHost>
<Directory /var/html/blog/>
Require all granted
</Directory>
|
重启Apache服务
1
|
$ systemctl restart httpd.service
|
测试web访问
1
2
3
4
|
[root@centos7-1 httpd] $ for name in www bbs blog;do curl $name.centos7.com;done;
http://www.centos7.com
http://bbs.centos7.com
http://blog.centos7.com
|
参考