标签:linux
apache虚拟主机的使用
虚拟主机技术是使用一台服务器实现发布多个网站的技术。
实现一台服务器多个网站的方法有:基于网卡,基于端口,基于域名。
基于网卡:一台主机添加多块网卡,就相当于有多个IP
基于端口:一台主机通过同一个IP不同的端口
基于域名:一台主机通过同一个IP同一个端口不通的域名
Rpm版apache文件路径:
配置文件路径:/etc/httpd/conf/httpd.conf
网站根文件路径:/var/www/html/index.html
执行命令文件路径:/usr/sbin
日志文件路径:/var/log/httpd
源码版apache文件路径:
配置文件路径:/usr/local/apache/conf
网站根文件路径:/usr/local/apache/htdocs
执行命令文件路径:/usr/local/apache/bin
日志文件路径:/usr/local/apache/logs
Linux基于域名搭建虚拟主机实现不同网站发布步骤:
v 配置静态IP,关闭防火墙,注意apache的安装方式。
[root@linux Desktop]# ifconfig eth0 192.168.1.1
[root@linux Desktop]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@linux Desktop]# iptables -F
[root@linux Desktop]# service iptables save
[root@linux Desktop]# setenforce 0
[root@linux Desktop]# vim /etc/sysconfig/selinux
[root@linux Desktop]# service httpd status
v 配置DNS,使用linux搭建bind服务器。
[root@linux /]# rpm -ivh /media/RHEL_6.4\ x86_64\ Disc\ 1/Packages/bind-9.8.2-0.17.rc1.el6.x86_64.rpm
[root@linux etc]# vim /etc/named.conf
修改参数:
options {
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query { any; };
zone "." IN {
type hint;
file "named.ca";
};
zone "a.com" IN {
type master;
file "a.zone";
};
zone "b.com" IN {
type master;
file "b.zone";
};
[root@linux named]# cp /var/named/named.empty a.zone
[root@linux named]# vim a.zone
添加参数:www A 192.168.1.1
[root@linux named]# chown named.named a.zone
[root@linux named]# cp a.zone b.zone
[root@linux named]# service named restart
v 配置apache配置文件,打开vhost开关。
源码版:
[root@linux conf]# vim /usr/local/apache/conf/httpd.conf
注释内容:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
[root@linux conf]# vim /usr/local/apache/conf/extra/httpd-vhosts.conf
修改参数:
<VirtualHost *:80>
ServerAdmin 867218859@qq.com
DocumentRoot "/usr/local/apache/htdocs/a"
ServerName www.a.com
ErrorLog "/usr/local/apache/logs/error.log"
CustomLog "/usr/local/apache/accesslog/access.log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin 867218859@qq.com
DocumentRoot "/usr/local/apache/htdocs/b"
ServerName www.b.com
ErrorLog "/usr/local/apache/logs/error.log"
CustomLog "/usr/local/apache/accesslog/access.log" common
</VirtualHost>
v 创建相关文件夹和文件
[root@linux apache]# mkdir accesslog
[root@linux apache]# mkdir accesslog
[root@linux apache]# mkdir /usr/local/apache/htdocs/a
[root@linux apache]# mkdir /usr/local/apache/htdocs/b
[root@linux a]# echo jintiantianqibucuo > index.html
[root@linux b]# echo mingtianhuigenghao >index.html
使用用户密码安全性登陆访问网页:
v 创建用户认证数据文件并创建一个用户:
[root@linux Desktop]# htpasswd -c /usr/local/apache/conf/.passwd ren
注释:-c:表示创建一个数据文件,没有改选项则是添加一个用户
v 添加用户授权配置:
[root@linux Desktop]# vim /usr/local/apache/conf/httpd.conf
添加参数:
<directory "/usr/local/apache/htdocs/a">
authname "ren"
authtype basic
authuserfile /usr/local/apache/conf/.passwd
require valid-user
</directory>
标签:linux
原文地址:http://10978134.blog.51cto.com/10968134/1945766