码迷,mamicode.com
首页 > Web开发 > 详细

Apache相关配置

时间:2016-05-16 11:16:06      阅读:309      评论:0      收藏:0      [点我收藏+]

标签:apache相关配置

上一篇文章 我们记录了 Apache的整个安装过程

http://771541213.blog.51cto.com/10810853/1773329


现在我们讲解一下 Apache的一些基本配置

a > 基于域名配置虚拟网站

b > 基于IP地址配置

c > 基于不同端口配置

d > 禁止列表网站的目录结构(危险)

e > 日志轮询配置 基于cronlog插件

f > httpd.conf扩展配置

g > 启动FQDN问题


A.基于域名配置虚拟网站

 1.先要打开apache扩展相关配置 把前面的 # 去掉

 技术分享

 2.编辑/application/apache/conf/extra/httpd-vhosts.conf

[root@oldboyLinux extra]# pwd
/application/apache/conf/extra
[root@oldboyLinux extra]# vim httpd-vhosts.conf

 3.在httpd-vhosts.conf把内容修改成以下这样

NameVirtualHost *:80

<VirtualHost *:80>
    ServerAdmin 771541213@qq.com
    DocumentRoot "/var/html/zsphp"
    ServerName www.zsphp.com
    ServerAlias zsphp.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

 4.在主配置文件httpd-conf里面新增一个节点权限配置 针对 /var/html/

  如果不对目录进行配置访问相应权限 可能会报403错误信息

<Directory "/var/html">
        Options FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

 5.配置本地hosts解析 进入测试连接....

127.0.0.1    oldboyLinux
::1          oldboyLinux
172.16.30.10 www.zsphp.com

6.利用curl模拟请求一下

[root@oldboyLinux conf]# curl -I www.zsphp.com
HTTP/1.1 200 OK
Date: Sun, 08 May 2016 01:51:13 GMT
Server: Apache/2.2.31 (Unix) DAV/2
Last-Modified: Sun, 08 May 2016 01:05:01 GMT
ETag: "bf574-e-5324a4809509e"
Accept-Ranges: bytes
Content-Length: 14
Content-Type: text/html

 现在你可以利用浏览器进行访问 不过也要配置一下本地 hosts解析到这台服务器

 如果不能访问  请关闭防火墙和SELinux




B.基于IP地址进行配置相关不同主机

 

 1.给服务器新增不同的IP地址 

  以下只是在命令行临时生效 重起网卡就失效了....

[root@oldboyLinux ~]# ifconfig eth0:1 172.16.30.11/16
[root@oldboyLinux ~]# ifconfig eth0:2 172.16.30.12/16
[root@oldboyLinux ~]# ifconfig 
eth0      Link encap:Ethernet  HWaddr 00:0C:29:3E:D0:64  
          inet addr:172.16.30.10  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fe3e:d064/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:17823 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12887 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:14481492 (13.8 MiB)  TX bytes:1799771 (1.7 MiB)

eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:3E:D0:64  
          inet addr:172.16.30.11  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

eth0:2    Link encap:Ethernet  HWaddr 00:0C:29:3E:D0:64  
          inet addr:172.16.30.12  Bcast:172.16.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:103 errors:0 dropped:0 overruns:0 frame:0
          TX packets:103 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:8780 (8.5 KiB)  TX bytes:8780 (8.5 KiB)

 删除多余网卡命令

[root@oldboyLinux ~]# ip addr del 172.16.30.11 dev eth0

2.编辑 httpd-vhosts.conf

 NameVirtualHost 名称虚拟主机

 基于IP地址配置 要把 #NameVirtualHost *:80 注释或者删除掉 

<VirtualHost 172.16.30.11:80>
    ServerAdmin 771541213@qq.com
    DocumentRoot "/var/html/web11"
    ServerName 172.16.30.11
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost 172.16.30.12:80>
    ServerAdmin 771541213@qq.com
    DocumentRoot "/var/html/web12"
    ServerName 172.16.30.12
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>


3.重起apache服务

[root@oldboyLinux extra]# /application/apache2.2.27/bin/apachectl graceful

4.利用curl请求 172.16.30.11 172.16.30.12

[root@oldboyLinux extra]# curl 172.16.30.11
<h1>172.16.30.11</h1>
[root@oldboyLinux extra]# curl 172.16.30.12
<h1>172.16.30.12</h1>


C.基于不同访问端口进行访问

123

Apache相关配置

标签:apache相关配置

原文地址:http://771541213.blog.51cto.com/10810853/1773786

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!