设为首页 收藏本站
查看: 1035|回复: 0

[经验分享] APACHE服务的配置。

[复制链接]

尚未签到

发表于 2017-1-2 09:48:00 | 显示全部楼层 |阅读模式
APACHE服务的配置。
APACHE的简介.
APACHE是世界上最流行的Web服务器软件之一,当然,提供WWW服务的还有微软的IIS,它是由微软开发的,只能用在微软的操作系统上,而APACHE是一个自由软件。说到APACHE,还要联想到LAMP,这个近年来也是应用得非常广泛,LAMP就是:linux+apache+mysql+phpApache的特点是简单、速度快、性能稳定。
APACHE的安装。
配置IP地址:
[iyunv@rhel ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
IPADDR=192.168.100.101
NETMASK=255.255.255.0  
[iyunv@rhel ~]# service network restart
安装apache
首先安装下面这两个软件:
[iyunv@rhel ~]# rpm -ivh /misc/cd/Server/apr-1.2.7-11.el5_3.1.i386.rpm
[iyunv@rhel ~]# rpm -ivh /misc/cd/Server/apr-util-1.2.7-11.el5.i386.rpm
现在才能安装httpd
[iyunv@rhel ~]# rpm -ivh /misc/cd/Server/httpd-2.2.3-43.el5.i386.rpm
APACHE简单的配置。
[iyunv@rhel ~]# service httpd start        //启动服务。
现在就可以测试一下了。如图,如下在地址栏输入http://192.168.100.101,出现如下画面,就说明httpd正常运行了。
DSC0000.jpg
如果想把这个页面换成自己的网页,只需把写好的文件放入/var/www/html下面即可,下面举个简单的例子。如:
[iyunv@rhel ~]# echo chenbin.blog.iyunv.com -> /var/www/html/index.html
访问测试一下: DSC0001.jpg
 
用户的个人网站。
[iyunv@rhel ~]# vi /etc/httpd/conf/httpd.conf
:set number              //显示行号
找到<IfModule mod_userdir.c>,在下面有
UserDir disable
#UserDir public_html
改成:
#UserDir disable
UserDir public_html
[iyunv@rhel ~]# service httpd restart
创建目录和网页文件。如果希望每个新建的用户都有一个www目录,只需在/etc/skel/下添加www目录即可,因为每个用户的默认目录都是参考/etc/skel的目录。
[iyunv@rhel ~]# mkdir public_html
[iyunv@rhel ~]# chmod 755 public_html              //修改权限。
[iyunv@rhel chenbin]# chmod 755 ~
[iyunv@rhel ~]# echo hello > public_html/index.html
 
测试:
DSC0002.jpg
注意:在地址栏里输入的是http://IP地址或主机名/~root。在root前面有个~,在键盘ESC键下面(数字1左边)那个键,要同时按住shift键。
那么有没有办法不输入那个~呢,当然是有的,最简单的方法就是添加一个链接:
[iyunv@rhel ~]# cd /var/www/html/
[iyunv@rhel html]# ln -s /root/public_html/ root   //创建一个链接,因为这里是root帐户,所以是/root/public _html,如果是其他用户,应该是/home/用户名/public_html
DSC0003.jpg
如果不想别人知道你的用户名,也可以把链接后面跟的用户名换成你想要的名字,如:
[iyunv@rhel html]# ln -s /root/public_html/ linux
再访问:
DSC0004.jpg
当然还有别的方法,将在下面介绍。
现在如果我们有多个网站,但只有一个IP地址,那怎么让别人能同时访问这多个网站呢?
相同IP不同端口的虚拟主机。
假设我们有一个IP192.168.100.101,有两个网站,我们可以使用两个端口,比如:一个使用81,一个使用82
首先,把两个网站的目录和文件建立好。
[iyunv@rhel html]# cd /var/www
[iyunv@rhel www]# mkdir html1
[iyunv@rhel www]# mkdir html2
[iyunv@rhel www]# echo html1 > html1/index.html
[iyunv@rhel www]# echo html2 > html2/index.html
修改配置文件:
[iyunv@rhel html]# vi /etc/httpd/conf/httpd.conf
Listen 80      //在这下面添加两个端口
Listen 81
Listen 82
 
在最后添加:
<VirtualHost 192.168.100.101:81>
        DocumentRoot /var/www/html1
</VirtualHost>
 
<VirtualHost 192.168.100.101:82>
        DocumentRoot /var/www/html2
</VirtualHost>
修改完成,重启服务:
[iyunv@rhel www]# service httpd restart
测试:
DSC0005.jpg
这时访问的时候有点不一样了,需要在IP地址后面加上:再加上端口号。
DSC0006.jpg
都可以访问,这就完成了。
不同IP相同端口的虚拟主机。
知道相同IP不同端口的配置了,这里相同端口不同IP就简单了,就按照上面的思路做。
因为是多个IP,所以这里就要配置多个IP地址,这里就配置子接口。
[iyunv@rhel www]# ifconfig eth0:0 192.168.100.111 up
[iyunv@rhel www]# ifconfig eth0:1 192.168.100.112 up
创建目录和网页文件:
[iyunv@rhel www]# mkdir html3
[iyunv@rhel www]# mkdir html4
[iyunv@rhel www]# echo html3 > html3/index.html
[iyunv@rhel www]# echo html4 > html4/index.html
修改配置文件:
[iyunv@rhel www]# vi /etc/httpd/conf/httpd.conf
至于端口,就使用默认的80端口。
<VirtualHost 192.168.100.111:80>
        DocumentRoot /var/www/html3
</VirtualHost>
 
<VirtualHost 192.168.100.112:80>
        DocumentRoot /var/www/html4
</VirtualHost>
重启服务:
[iyunv@rhel www]# service httpd restart
测试:
DSC0007.jpg
下一个:
DSC0008.jpg
这个也就完成了。
使用域名的虚拟主机。
基于域名的虚拟主机,这就要用到DNS了,那么首先把DNS配置一下吧,虽然前面有配置DNS的详细说明,但这里还是简单配置一下,就当复习一下。
安装DNS软件:
[iyunv@rhel www]# cd /misc/cd/Server/
[iyunv@rhel Server]# rpm -ivh bind-9.3.6-4.P1.el5_4.2.i386.rpm
[iyunv@rhel Server]# rpm -ivh bind-chroot-9.3.6-4.P1.el5_4.2.i386.rpm
[iyunv@rhel Server]# rpm -ivh bind-utils-9.3.6-4.P1.el5_4.2.i386.rpm
[iyunv@rhel Server]# rpm -ivh caching-nameserver-9.3.6-4.P1.el5_4.2.i386.rpm
 
[iyunv@rhel Server]# cd ~
[iyunv@rhel ~]# vi /var/named/chroot/etc/named.caching-nameserver.conf
        listen-on port 53 { 192.168.100.101; };             //修改一下IP地址。
        allow-query     { any; };         //允许所有人查询。
        match-clients      { any; };     //允许所有客户端。
        match-destinations { any; };     //允许所有目标。
 
创建区域:
[iyunv@rhel ~]# vi /var/named/chroot/etc/named.rfc1912.zones            
添加以下区域:
zone "rhel1.com" IN {
        type master;
        file "rhel1.com.zone";
        allow-update { none; };
};
zone "rhel2.com" IN {
        type master;
        file "rhel2.com.zone";
        allow-update { none; };
};
修改区域配置文件;
[iyunv@rhel ~]# cd /var/named/chroot/var/named/
[iyunv@rhel named]# cp -p localhost.zone rhel1.com.zone     //别忘了加-p
[iyunv@rhel named]# cp -p localhost.zone rhel2.com.zone
[iyunv@rhel named]# vi rhel1.com.zone
www             IN A            192.168.100.101      //添加这一行
[iyunv@rhel named]# vi rhel2.com.zone
www             IN A            192.168.100.101      //也是添加这一行
 
配置完成,重启一下服务。
[iyunv@rhel named]# service named restart
 
来测试一下DNS:如图:
DSC0009.jpg
DNS配置就可以了,下面接下来配置:
[iyunv@rhel named]# cd /var/www/
[iyunv@rhel www]# mkdir html5
[iyunv@rhel www]# mkdir html6
[iyunv@rhel www]# echo www.rhel1.com > html5/index.html
[iyunv@rhel www]# echo www.rhel2.com > html6/index.html
[iyunv@rhel www]# vi /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.100.101
<VirtualHost 192.168.100.101>
        ServerName www.rhel1.com
        DocumentRoot /var/www/html5
</VirtualHost>
 
<VirtualHost 192.168.100.101>
        ServerName www.rhel2.com
        DocumentRoot /var/www/html6
</VirtualHost>
配置完成,重启服务。
[iyunv@rhel www]# service httpd restart
 
现在可以测试了,但现在访问还不行,我们还得把用作测试的主机的DNS指向192.168.100.101,关于指定DNS就不演示了,这个太简单了,接下来就可以测试了。如图:
DSC00010.jpg
第二个:
DSC00011.jpg
好了,基于域名的虚拟主机就到这里。
虚拟目录。
虚拟目录也可以说是别名,也就是可以使用多个名称来访问一个目录。比如,在上面说的那个访问时要加个~的,我们使用了一个链接可以解决,这里就使用另一种方法来解决,虚拟目录。
[iyunv@rhel www]# vi /etc/httpd/conf/httpd.conf
添加如下几行:
Alias /rhel "/root/public_html/"         //注意:在/rhel后面不要加上/
<Directory "/root/public_html/">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>
[iyunv@rhel www]# service httpd restart
DSC00012.jpg
完成。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-322713-1-1.html 上篇帖子: apache日志分析简介 下篇帖子: 使用Apache Commons Pool
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表