Apache虚拟主机实战

Posted 夕颜@伤雨痕

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Apache虚拟主机实战相关的知识,希望对你有一定的参考价值。

 

[root@localhost ~]# wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.32.tar.bz2 

[root@localhost ~]# yum install -y apr-util apr-devel apr-util-devel

[root@localhost ~]# tar jxvf httpd-2.2.32.tar.bz2 

[root@localhost ~]# cd httpd-2.2.32
[root@localhost httpd-2.2.32]# ./configure --prefix=/usr/local/httpd --enable-rewrite --enable-so

[root@localhost httpd-2.2.32]# make 

[root@localhost httpd-2.2.32]# make install

 

[root@localhost httpd-2.2.32]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@localhost httpd-2.2.32]# httpd -t
httpd: Could not reliably determine the server\'s fully qualified domain name, using localhost.localdomain for ServerName
Syntax OK

[root@localhost httpd-2.2.32]# /usr/local/httpd/bin/apachectl start

[root@localhost httpd-2.2.32]# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 10535 root 4u IPv6 34976 0t0 TCP *:http (LISTEN)
httpd 10536 daemon 4u IPv6 34976 0t0 TCP *:http (LISTEN)
httpd 10537 daemon 4u IPv6 34976 0t0 TCP *:http (LISTEN)
httpd 10538 daemon 4u IPv6 34976 0t0 TCP *:http (LISTEN)
httpd 10539 daemon 4u IPv6 34976 0t0 TCP *:http (LISTEN)
httpd 10540 daemon 4u IPv6 34976 0t0 TCP *:http (LISTEN)

【apache虚拟主机生产应用】

 [root@localhost ~]# cd /usr/local/httpd/htdocs/

[root@localhost htdocs]# mkdir www1 www2
[root@localhost htdocs]# ls
www1 www2

[root@localhost ~]# vim /usr/local/httpd/conf/httpd.conf         #开启虚拟主机认证模块功能

[root@localhost htdocs]# vim /usr/local/httpd/conf/extra/httpd-vhosts.conf

NameVirtualHost *:80   #指定一个机遇域名的虚拟主机将使用哪个IP地址接受请求

<VirtualHost *:80>
ServerAdmin bixiaoyu@staff.hexun.com
DocumentRoot "/usr/local/httpd/htdocs/www1"
ServerName www.wugk1.com
<Directory "/usr/local/httpd/htdocs/www1">             #设置指定目录的访问权限,
AllowOverride All               #AllowOveride设置None时,.htaccess文件将被忽略,指令设置为All时,所有具有“.htaccess”作用域将生效
Options -Indexes FollowSymLinks         #  禁止显示目录,如果要以目录显示需要改成Options Indexes FollowSymLinks
Order allow,deny           #默认情况下禁止所有客户端访问,order deny,allow默认情况下允许所有客户端访问,
Allow from all       #允许所有客户端访问
</Directory>
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>

<VirtualHost *:80>
ServerAdmin bixiaoyu@staff.hexun.com
DocumentRoot "/usr/local/httpd/htdocs/www2"
ServerName www.xiaoyu.com
<Directory "/usr/local/httpd/htdocs/www2">
AllowOverride All
Options -Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>

[root@localhost ~]# vim /etc/hosts        #在本地和服务器上配置域名解析,随后即可!

192.168.2.139 www.xiaoyu.com,www.test.com

[root@localhost ~]# /usr/local/httpd/bin/apachectl restart     #重启生效

 

以上是关于Apache虚拟主机实战的主要内容,如果未能解决你的问题,请参考以下文章

[原创]实战之Ansible生成Apache多主机配置

Nginx常用功能配置实战

分享 apache 服务器的实战经验 1

20170830L08-06老男孩linux实战运维培训-Lamp系列之-Apache服务生产实战应用指南03

Tomcat部署实战!

Tomcat(tomcat虚拟主机,Tomcat日志,单机多实例配置实战,JVM设置和连接数设置)