Linux下Apache服务器配置

相关包:
httpd-2.2.3-29.e15.i386.rpm                 //主程序包
httpd-devel-2.2.3-29.e15.i386.rpm        //开发程序包
httpd-manual-2.2.3-29.e15.i386.rpm     //手册文档
system-config-httpd-1.3.3.3-1.e15.noarch.rpm   //配置工具
注:安装时会出现依赖包问题,可用YUM安装来解决
   启用时需要配置防火墙来放行
 
开机自动加载:
chkconfig --level 3 httpd on 
 
配置实例:
例1:部门内搭建一台WEB服务器,采用的IP地址和端口为192.168.0.3:80,首页采用index.html文件。管理员E- mail地址为root@sales.com,网页的编码类型采用GB2312,所有网站资源都存放在/var/www/html目录下,并将 Apache的根目录设置为/etc/httpd目录。
编辑主配置文件httpd.conf
vim /etc/httpd/conf/httpd.conf    //编辑主配置文件
ServerRoot "/etc/httpd"             //设置Apache的主目录
Timeout 120                             //设置请求超时
Listen 80                                  //设置监听端口
ServerAdmin root@sales.com          //设置管理员邮箱
ServerName 192.168.0.3:80           //设置主机或IP
DocumentRoot "/var/www/html"      //设置Apache文档目录
DirectoryIndex index.html               //设置主页文件
AddDefaultCharset GB2312            //设置网站编码
编辑主页文件用作测试:
cd /var/www/html
echo "This is web test sample.">>index.html
chmod 705 index.html
重新加载服务:
service httpd restart
 
例2:假设Apache服务器具有192.168.0.2和19.16.0.3两个地址,然后配置Apache,把多个网站绑定在不同的IP地址上,访问服务器上不同的IP地址,就可以看到不同的网站。
(基于IP)
mkdir /var/www/ip1   /var/www/ip2           //创建两个主目录
编辑httpd.conf文件:
<Virtualhost 192.168.0.2>                      //设置虚拟主机的IP
   DocumentRoot /var/www/ip1                //设置虚拟主机的主目录
   DirectoryIndex index.html                    //设置主页文件
   ServerAdmin root@sales.com               //设置管理员邮箱
   ErrorLog  logs/ip1-error_log                 //设置错误日志的存放位置
   CustomLog  logs/ip1-access_log common       //设置访问日志的存放位置
</Virtualhost>
<Virtualhost 192.168.0.3>                      //设置相应的IP
   DocumentRoot /var/www/ip2
   DirectoryIndex index.html
   ServerAdmin root@sales.com
   ErrorLog  logs/ip2-error_log
   CustomLog  logs/ip2-access_log common
</Virtualhost>
 
(基于域名)
mkdir /var/www/smile   /var/www/long         //创建两个主目录
编辑httpd.conf文件:
<Virtualhost 192.168.0.3>                         //设置虚拟主机的IP
   DocumentRoot /var/www/smile                //设置虚拟主机的主目录
   DirectoryIndex index.html                       //设置主页文件
   ServerName www.smile.com                    //设置虚拟主机完全域名
   ServerAdmin root@sales.com                  //设置管理员邮箱
   ErrorLog  logs/smile-error_log                 //设置错误日志的存放位置
   CustomLog  logs/smile-access_log common     //设置访问日志的存放位置
</Virtualhost>
<Virtualhost 192.168.0.3>
   DocumentRoot /var/www/long
   DirectoryIndex index.html
   ServerName www.smile.com                     //设置虚拟主机完全域名
   ServerAdmin root@sales.com
   ErrorLog  logs/long-error_log
   CustomLog  logs/long-access_log common
</Virtualhost>
 
(基于端口)
mkdir /var/www/port8080   /var/www/port8090        //创建两个主目录
编辑httpd.conf文件:
Listen 8080
Listen 8090
<Virtualhost 192.168.0.3:8080>                            //设置相应的端口
   DocumentRoot /var/www/port8080                     //设置虚拟主机的主目录
   DirectoryIndex index.html                                  //设置主页文件
   ServerAdmin root@sales.com                             //设置管理员邮箱
   ErrorLog  logs/port8080-error_log                     //设置错误日志的存放位置
   CustomLog  logs/port8080-access_log common  //设置访问日志的存放位置
</Virtualhost>
<Virtualhost 192.168.0.3:8090>                          //设置相应的端口
   DocumentRoot /var/www/port8090
   DirectoryIndex index.html
   ServerAdmin root@sales.com
   ErrorLog  logs/port8090-error_log
   CustomLog  logs/port8090-access_log common
</Virtualhost>

Linux下Apache服务器配置的更多相关文章

  1. [Linux]Linux下Apache服务器配置

    Linux下Apache服务器配置 相关包: httpd-2.2.3-29.e15.i386.rpm                 //主程序包 httpd-devel-2.2.3-29.e15.i ...

  2. linux 下 apache相关;启动、停止、重启命令;配置文件位置等等

    linux 下 apache启动.停止.重启命 基本的操作方法: 本文假设你的apahce安装目录为/usr/local/apache2,这些方法适合任何情况 apahce启动命令: 推荐/usr/l ...

  3. Linux下apache+phppgadmin+postgresql安装配置

    Linux下apache+phppgadmin+postgresql安装配置 操作系统:CentOS 安装包:httpd(首选yum), php(包括php以及php-pgsql,php-mbstri ...

  4. 分享:linux下apache服务器的配置和管理

    linux下apache服务器的配置和管理. 一.两个重要目录: Apache有两个重要的目录:1.配置目录/etc/httpd/conf:2.文档目录/var/www: 二.两种配置模式: Apac ...

  5. linux 下apache安装、启动和配置

    linux 下 apache安装 1:系统安装,这里就不说了,网上有很多,也很简单.顺便说下,我用的是redhat 9: 2:在图形界面下下载apache 安装包,我下的是 httpd-2.2.9.t ...

  6. linux 下 apache启动、停止、重启命令

    原文:linux 下 apache启动.停止.重启命令 基本的操作方法: 本文假设你的apahce安装目录为/usr/local/apache2,这些方法适合任何情况 apahce启动命令: 推荐/u ...

  7. MAC下 Apache服务器配置

    今天做了一个注册登录提交的页面,后续操作需要用到后端的知识 php+Mysql,之前只是有些了解,现在开始具体操作了,首先从配置环境开始.查了好几篇文档与博客,了解了挺多知识. Mac下Apache服 ...

  8. Linux下Apache服务部署静态网站------网站服务程序

    文章链接(我的CSDN博客): Linux下Apache服务部署静态网站------网站服务程序

  9. linux下apache和tomcat整合

    一 Apache与Tomcat比较联系 apache支持静态页,tomcat支持动态的,比如servlet等. 一般使用apache+tomcat的话,apache只是作为一个转发,对jsp的处理是由 ...

随机推荐

  1. Canvas绘制不规则图形,实现可拖动,编辑--V1.0第一篇

    目前的工作在做在线的标注工具,接触canvas一年了,各种绘制,基本上图像的交互canvas都可以完成,也写了几篇关于canvas的文章,遇到的问题也写博客上了,对于canvas有问题的朋友可以去看看 ...

  2. javascript的几种使用多行字符串的方式

    JS里并没有标准的多行字符串的表示方法,但是在用模板的时候,为了保证模板的可阅读性,我们又不可避免的使用多行字符串,所以出现了各种搞法,这里以一段jade的模板作为示例,简单总结和对比一下. 字符串相 ...

  3. linux五大搜索命令学习

    五大搜索命令学习 分别解释locate,find,which,whereis,grep 五大linux搜索命令 locate 解释:由man手册可以看出,locate查找就是根据文件名进行查找,只是依 ...

  4. css3 transform matrix矩阵的使用

      Transform 执行顺序问题 — 后写先执行 matrix(a,b,c,d,e,f) 矩阵函数 •通过矩阵实现缩放 x轴缩放 a=x*a    c=x*c     e=x*e; y轴缩放 b= ...

  5. 三重Des对称加密在Android、Ios 和Java 平台的实现

    引言      如今手机app五彩缤纷,确保手机用户的数据安全是开发人员必须掌握的技巧,下面通过实例介绍DES在android.ios.java平台的使用方法: DES加密是目前最常用的对称加密方式, ...

  6. 多进程回声服务器/客户端【linux】

    并发服务器端 #include <unistd.h> #include <stdio.h> #include <sys/wait.h> #include <c ...

  7. C#学习历程(六)[ref 关键字的使用]

    ref 关键字的使用 ref 关键字通过引用(而非值)传递参数. 通过引用传递的效果是,对所调用方法中的参数进行的任何更改都反映在调用方法中. 例如,如果调用方传递本地变量表达式或数组元素访问表达式, ...

  8. Annotation方式实现AOP

    1.添加其他jar包 2.配置applicationContext.xml文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 <?xml version=&quo ...

  9. 12.18 webSocket消息推送

    ---恢复内容开始--- 准备工作: 在要跳转到的页面加入js <#--弹窗--> <div class="modal fade" id="myModa ...

  10. L158

    It started out modestly enough: David Hertz, having learned that under the right conditions you real ...