Apache服务器的安装与配置
- 格式:doc
- 大小:23.00 KB
- 文档页数:2
每日一句:I am a slow walker, but I never walk backwards.(我走得很慢,但从来不后退。
)一、本次配置a)操作系统:Linuxb)服务器:httpd-2.4.3.tar.gzc)APR:apr-1.4.6.tar.gzd)APR-Util:apr-util-1.5.1.tar.gze)PCRE:pcre-8.31.tar.gz二、Linux安装程序的基本步骤1、./configure --prefix=安装目录2、make3、make install三、Linux安装apache服务器步骤:1、gzip -d httpd- NN.tar.gz (阿帕奇服务器安装包)2、tar xvf httpd- NN.tar(执行第一步后出现这个文件)3、cd httpd- NN(执行完第二步后会产生一个服务器的目录,使用cd命令进入)4、安装程序的基本步骤5、安装目录/bin/apachectl -k start (启动服务器)6、测试。
打开浏览器输入http://服务器IP,如果出现It Works,则服务器安装成功7、安装过程中遇到的问题a)安装服务器时提示缺少apr文件(到官网下载后进行安装(还是按照安装步骤))b)安装apr时提示确实apr-util(到官网下载后进行安装(还是按照安装步骤))c)安装服务器时提示确实pcre(到官网下载后进行安装(还是按照安装步骤))四、配置apache的虚拟主机a)将“安装目录\conf\httpd.conf ”中“#Include etc/extra/httpd-vhosts.conf ”的#去掉。
这样才能使httpd-vhosts.conf文件起作用,或者直接在httpd.conf中写配置也可以(不建议这么做)b)在httpd-vhosts.conf中配置VirtualHost(注:Apache在接受到请求时,首先会默认第一个VirtualHost,然后再找匹配的,如果没有匹配的,默认就是第一个VirtualHost起作用)<VirtualHost *:80> #主机名ServerAdmin admin@ #如果服务器有任何问题将发信到这个地址DocumentRoot /www/ #虚拟主机的指向目录ServerName #访问主机的域名[:端口号]ServerAlias * #- -这个不知道是啥。
CentOS7Apache服务的安装与配置⼀、Apache简介Apache 是⼀个知名的开源Web服务器。
早期的Apache服务器由Apache Group来维护,直到1999年6⽉Apache Group在美国德拉⽡市成⽴了⾮盈利性组织的公司,即Apache软件基⾦会(Apache Software Foundation,ASF)。
⽹站需要web服务器来架构,⽹页设计美⼯⼈员(flash,dreamweaver,firework,photoshop等),⽹页开发⼈员(php,.net,jsp等),⽹站建⽴好后,需要我们维护,优化,排错,架构延伸扩容等。
简单点说就是我们如果要浏览⼀个⽹页的话,基本上所有的⽹站都使⽤的是http协议来进⾏数据传输的!⾄于怎么样传输,我们做为运维来说就没有必要去深究了,那是做html前端开发⼈员要去考虑的事情!Apache由内核、标准模块和第三⽅提供的模块三个层次组成。
通常Apache在默认安装时,只安装图中的1、2两部分。
根据⽤户需要,⽤户可以通过修改配置去掉⼀些默认安装的标准模块;也可以通过修改配置安装⼀些默认不安装的模块。
同时,如果⽤户需要,也可以安装⼀些第三⽅提供的模块。
[此⽹站会有每⽉份的世界上⽹站使⽤的WEB服务器的使⽤率统计](https:///archives/category/web-server-survey/)Apache是世界上应⽤最⼴泛的web服务器之⼀[ Apache官⽹](/)⼆、CentOS下的Apache1. ⽹站分为两种静态⽹站:Apache,Nginx,html动态⽹站:php/perl/python,jsp(java), .net2. Apache服务概览软件包: httpd, httpd-devel, httpd-manual服务类型:由systemd启动的守护进程配置单元: /usr/lib/systemd/system/httpd.service守护进程: /usr/sbin/httpd端⼝: 80(http), 443(https)配置: /etc/httpd/Web⽂档: /var/www/html/Apache⽇志记录⽬录:/var/log/httpd/该⽬录下有两种⽂件:access_log # 记录客户端访问Apache的信息,⽐如客户端的iperror_log # 记录访问页⾯错误信息Apache服务启动的记录⽇志:/var/log/messages # 这个⽇志是系统的⼤集合3. 配置Apache服务器的准备⼯作系统平台: CentOS 7.3DHCP Server: 192.168.1.20第1步:服务器设置静态IP第2步:更改主机名,写/etc/hosts记录[root@Apache ~]# echo "192.168.1.20 Apache" >> /etc/hosts --往/etc/hosts添加ip和主机名[root@Apache ~]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6192.168.1.20 Apache第3步:关闭防⽕墙[root@Apache ~]# systemctl stop firewalld --临时关闭防⽕墙[root@Apache ~]# systemctl disable firewalld --永久关闭防⽕墙第4步:关闭selinux临时关闭:[root@Apache ~]# setenforce 0setenforce: SELinux is disabled永久关闭:[root@Apache ~]# vim /etc/selinux/configSELINUX=disabled # 将enforcing改为disabled[root@Apache ~]# reboot --重启系统永久⽣效三、Apache服务的搭建与配置1. 使⽤yum包安装Apache软件[root@Apache ~]# yum -y install httpd*[root@Apache ~]# rpm -qa | grep httpd --查看安装的http包httpd-manual-2.4.6-67.el7.centos.6.noarchhttpd-tools-2.4.6-67.el7.centos.6.x86_64httpd-2.4.6-67.el7.centos.6.x86_64httpd-devel-2.4.6-67.el7.centos.6.x86_64安装成功后,会产⽣下⾯两个⽂件/etc/httpd/conf/httpd.conf # 主配置⽂件/var/www/html # 默认⽹站家⽬录2. 认识配置⽂件⾥的主要参数[root@Apache ~]# vim /etc/httpd/conf/httpd.conf31 serverRoot "/etc/httpd" # 存放配置⽂件的⽬录42 Listen 80 # Apache服务监听端⼝66 User apache # ⼦进程的⽤户67 Group apache # ⼦进程的组86 ServerAdmin root@localhost # 设置管理员邮件地址119 DocumentRoot "/var/www/html" --⽹站家⽬录# 设置DocumentRoot指定⽬录的属性131 <Directory "/var/www/html"> # ⽹站容器开始标识144 Options Indexes FollowSymLinks # 找不到主页时,以⽬录的⽅式呈现,并允许链接到⽹站根⽬录以外151 AllowOverride None # none不使⽤.htaccess控制,all允许156 Require all granted # granted表⽰运⾏所有访问,denied表⽰拒绝所有访问157 </Directory> # 容器结束164 DirectoryIndex index.html # 定义主页⽂件,当访问到⽹站⽬录时如果有定义的主页⽂件,⽹站会⾃动访问316 AddDefaultCharset UTF-8 # 字符编码,如果中⽂的话,有可能需要改为gb2312或者gbk,因你的⽹站⽂件的默认编码⽽异3. 启动Apache⽹站[root@Apache ~]# systemctl start httpd.service[root@Apache ~]# lsof -i:80 --查看httpd服务是否启动COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 20585 root 4u IPv6 402909 0t0 TCP *:http (LISTEN)httpd 20586 apache 4u IPv6 402909 0t0 TCP *:http (LISTEN)httpd 20587 apache 4u IPv6 402909 0t0 TCP *:http (LISTEN)httpd 20588 apache 4u IPv6 402909 0t0 TCP *:http (LISTEN)httpd 20589 apache 4u IPv6 402909 0t0 TCP *:http (LISTEN)httpd 20590 apache 4u IPv6 402909 0t0 TCP *:http (LISTEN)启动成功后使⽤浏览器:输⼊⾃⼰的IP地址会看到⼀个红帽的欢迎页⾯:[root@Apache ~]# firefox 192.168.1.20每次打开浏览器不是很⽅便,因此我们可以使⽤⽂本浏览器,⽅便测试。
Linux下Apache服务的部署和配置⽬录1 Apache的作⽤2 Apache的安装3 apache的启⽤4 apache的基本信息5 apache的访问控制5.1 基于客户端ip的访问控制5.2 基于⽤户认证的访问控制6 apache的虚拟主机7 apache的加密访问8 ⽹页重写9 正向代理10 反向代理11 apache ⽀持的语⾔1 Apache的作⽤解析⽹页语⾔,如html,php,jsp等接收web⽤户的请求,并给予⼀定的响应2 Apache的安装安装apche软件:dnf install httpd.x86_64 -y3 apache的启⽤开启apache服务并设置开机启动:systemctl enable --now httpd查看apache服务的状态:systemctl enable --now httpd查看⽕墙信息:firewall-cmd --list-all 在⽕墙中永久开启http服务:firewall-cmd --permanent --add-service=http在⽕墙中永久开启https服务: f irewall-cmd --permanent --add-service=https在不改变当前⽕墙状态的情况下刷新防⽕墙:firewall-cmd --reload4 apache的基本信息apche的基本信息服务名称:httpd主配置⽂件:/etc/httpd/conf/httpd.conf⼦配置⽂件:/etc/httpd/conf.d/*.conf默认发布⽬录:/var/www/html默认端⼝:80 (http),443(https)⽇志⽂件:/etc/httpd/logs开启apche服务后,输⼊ip查看默认发布页⾯:(1)更改apche服务的端⼝号查看httpd服务的默认端⼝号:netstat -antlupe |grep httpd编辑配置⽂件:/etc/httpd/conf/httpd.conf,修改端⼝号重启httpd服务:systemctl restart httpd查看httpd服务的端⼝号:netsat -antlupe | grep httpd更改端⼝号后,输⼊ip后⽆法正常连接,原因是8080端⼝未添加在⽕墙中在防⽕墙⾥添加888端⼝号:firewall-cmd --permanent --add-port=888/tcp在不改变当前⽕墙状态的情况下刷新防⽕墙:firewall-cmd --reload输⼊IP地址:端⼝号,可以正常访问(2)修改apche的默认发布⽂件默认⽬录:cd /var/www/html在⽂件默认发布⽬录下新建⼀个⽂件index.html输⼊:http://172.25.254.144查看默认发布⽂件就是访问apache时没有指定⽂件名,即默认访问的⽂件,此⽂件可以指定多个,但有访问顺序。
Linux下Apache的安装与配置⼀、编译安装1、解决依赖关系⼆、后续操作1、启动httpd两种⽅法:第⼀种、/usr/local/apache/bin/apachectl start第⼆种⽅法:先修改http.pid⽂件位置打开配置⽂件增加⼀⾏vim /etc/httpd/httpd.conf 增加PidFile “/var/run/httpd.pid”为了启动httpd更加⽅便,#!/bin/bash## httpd Startup script for the Apache HTTP Server## chkconfig: - 85 15# description: Apache is a World Wide Web server. It is used to serve \# HTML files and CGI.# processname: httpd# config: /etc/httpd/conf/httpd.conf# config: /etc/sysconfig/httpd# pidfile: /var/run/httpd.pid# Source function library.. /etc/rc.d/init.d/functionsif [ -f /etc/sysconfig/httpd ]; then. /etc/sysconfig/httpdfi# Start httpd in the C locale by default.HTTPD_LANG=${HTTPD_LANG-"C"}# This will prevent initlog from swallowing up a pass-phrase prompt if# mod_ssl needs a pass-phrase from the user.INITLOG_ARGS=""# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server# with the thread-based "worker" MPM; BE WARNED that some modules may not# work correctly with a thread-based MPM; notably PHP will refuse to start.# Path to the apachectl script, server binary, and short-form for messages.apachectl=/usr/local/apache/bin/apachectlhttpd=${HTTPD-/usr/local/apache/bin/httpd}prog=httpdpidfile=${PIDFILE-/var/run/httpd.pid}lockfile=${LOCKFILE-/var/lock/subsys/httpd}RETVAL=0start() {echo -n $"Starting $prog: "LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONSRETVAL=$?echo[ $RETVAL = 0 ] && touch ${lockfile}return $RETVAL}stop() {echo -n $"Stopping $prog: "killproc -p ${pidfile} -d 10 $httpdRETVAL=$?echo[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}}reload() {echo -n $"Reloading $prog: "if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; thenRETVAL=$?echo $"not reloading due to configuration syntax error"failure $"not reloading $httpd due to configuration syntax error"elsekillproc -p ${pidfile} $httpd -HUPRETVAL=$?fiecho}# See how we were called.case "$1" instart)start;;stop)stop;;status)status -p ${pidfile} $httpdRETVAL=$?;;restart)stopstart;;condrestart)if [ -f ${pidfile} ] ; thenstopstartfi;;reload)reload;;graceful|help|configtest|fullstatus)$apachectl $@RETVAL=$?;;*)echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1esacexit $RETVAL将以上代码加⼊到vim /etc/init.d/httpd中⽽后为此脚本赋予执⾏权限:chmod +x /etc/rc.d/init.d/httpd加⼊服务列表:chkconfig --add httpd给3,5启动chkconfig --level 3,5 httpd on最后加路径将 export PATH=$PATH:/usr/local/apache/binvim /etc/profile.d/httpd.sh完成后重新登录就可以了。
APACHE安装配置说明⼀、软件下载⼆、环境检查# rpm -qa|grep zlibzlib-devel-1.2.3-3zlib-1.2.3-3# rpm -qa|grep sslopenssl-devel-0.9.8b-10.el5openssl-0.9.8b-10.el5如果需要依赖包,安装其对应的devel包即可,此处仅⽤到zlib和ssl。
另,如果有httpd包,要先卸载掉或停⽌其服务。
三、编译安装1、针对安装⽬的的说明(来⾃INSTALL⽂件)如果是开发者则使⽤此选项,--with-included-apr利于连接apache的代码或者是调试apache,其消除了由于版本或者编译中跟APR或者APR-util代码产⽣的不匹配;如果从⼦版本编译apache,要先运⾏buildconf(需要Python,GNU autoconf和libtool),然后运⾏configure。
发⾏包不⽤。
如果要在FreeBSD5.4之前编译时包含apache的threaded MPM,需要使⽤--enable-threads和--with-mpm 参数在Mac上编译⼦版本,要使⽤GNU Libtool 1.4.2及以上版本2、关于SSL加密和正则表达式(来⾃⽂件README)Apache2.0及以上版本在⽬录modules/ssl/下包含了mod_ssl模块⽤于配置和监听ssl⽹络接⼝的连接。
(另外,⼀些apr-util版本在⽬录srclib/apr-util/ssl/下提供了ssl⽹络接⼝)带有单词crypto的包的名字,可能包含openssl加密库的⽬标代码。
如果apache的加密功能不理想或者要排除再重分配,则可以使⽤包的名字包含nossl的发布包。
Apache使⽤PCRE包包含的正则表达式。
3、对configure参数的说明配置帮助表:-h, --help显⽰帮助信息display this help and exit--help=short ⽤short参数将只显⽰正在运⾏的当前脚本的选项,⽽不能列出适⽤于Apache配置脚本所运⾏的外部配置脚本的选项display optionsspecific to thispackage--help=recursive 使⽤recursive参数将显⽰所有程序包的简短描述display the shorthelp of all theincluded packages-V, --version显⽰版本display version information and exit-q, --quiet, --silent不显⽰checking……信息do notprint`checking...' messages--cache-file=FILE在指定⽂件中存储测试结果cache test results in FILE [disabled]-C, --config-cache 在⽂件config.cache中存储测试结果alias for `--cachefile=config.cache'-n, --no-create configure脚本运⾏结束后不输出结果⽂件,常⽤于正式编译前的测试。
一、软件准备安装 Apache HTTP Server 和 配置PHP环境,要下载 “apache_2.2.4-win32-x86-no_ssl.msi”这两个文件 的不同版本在网上可以下载到,CSDN 上就有好多版本。
二、安装 Apache HTTP Server双击“apache_2.2.4-win32-x86-no_ssl.msi”开始安装出现 Windows 标准的软件安装欢迎界面,见图1图1 欢迎界面直接点“Next”继续,出现授权协议,见图2。
图2 授权协议选择“I accept the terms in the license agreement”同意授权协议,然后点“Next”继续图3 安装说明直接点“Next”下一步,出现填写信息界面,见图4。
图4 填写信息“Network Domain”填写你的网络域名,比如 mrsoft ,如果没有网络域名,可以随便填写。
但则一定要填写正确的网络域名。
“Server Name”填入你的服务器名,比如 will ,也就是主机名。
“Administrator's Email Address”填写系统管理员的联系电子邮件地址,比如 admin@163.c 上述三条信息仅供参考,其中联系电子邮件地址会在当系统故障时提供给访问者,三条信息均可下面有两个选择,图片上选择的是为系统所有用户安装,使用默认的80端口,并作为系统服务自另外一个是仅为当前用户安装,使用端口8080,手动启动。
图5 选择安装类型选择系统默认“Typical”安装,点“Next” ,出现如图6 系统默认的安装路径图6 系统默认的安装路径这里我更改安装路径(也可以不更改,根据个人习惯),点“Change”,选择你要安装的路径,图7 更改安装路径点击“OK”,如图8所示图8 更改后的安装路径直接点“Next”下一步,图9 准备安装确认安装选项无误,如果您认为要再检查一遍,可以点“Back”一步步返回检查。
Apache 配置一、安装Apache下载地址:/1. 安装Apache# tar zxvf httpd-2.2.11.tar.gz# cd httpd-2.2.11# ./configure --prefix=/usr/local/apache --enable-so//编译时加上加载模块参数--enable-so# make# make install2. 配置系统启动时自动启动Apache服务。
# vi /etc/rc.d/rc.local//在rc.local上加入一行/usr/local/apache/bin/apachectl –k start。
二、配置Apache1. 修改httpd.conf文件# vi /usr/local/apache/conf/httpd.conf1)设置根目录的路径根目录是指Apache存放配置文件和日志文件的目录,配置参数为ServerRoot,默认位于“/u sr/local/apache”。
命令如下:2)设置监听IP地址及端口号默认侦听本机所有IP地址的TCP80端口,命令如下:Listen 80用户也可以按自己的需求,使用多个Listen语句在多个地址和端口上侦听客户端请求。
比如:Listen 192.168.99.9:80Linsten 172.16.0.20:80803)设置系统管理员E-m ail使用ServerAdmin参数设置管理员E-m ail,比如管理员的Email地址为root@guoxuemin. cn:4)设置服务器主机的名称参数ServerName用来设置服务器的主机名称,如果没有域名则填入服务器的IP地址,比如服务器的IP地址为192.168.99.9:5)设置主目录的路径用户可以使用参数Document Root配置服务器主目录默认路径,比如,主目录路径为:6)设置默认文件Apache的默认文件名为index.ht ml,可以使用Directory Index参数来配置,比如,将ind ex.php设置为默认文件名:7)测试:打开浏览器,输入地址:http://192.168.99.9,可以打开站点了:2. 配置目录权限使用<Directory 目录路径>和</Directory>设置目录的权限。
Apache的安装及使⽤PHP最初是 Persional Home Page 的缩写,表⽰个⼈主页。
下载Apache进⼊apache服务器官⽹这⾥我们以下载稳定版的Apache httpd 2.4.39 Released 为例,点击download。
下载后解压,改名为httpd,放到D盘根⽬录。
Apache 各⽬录作⽤⽬录名说明bin Apache执⾏⽂件所在⽬录,如httpd.exe、ApacheMonitor.exe 等cgi-bin GCI⽹页程序存放⽬录conf Apache服务器配置⽂件所在⽬录error错误⽂件⽬录,⽤于保存因服务器设置或浏览器请求的数据错误时产⽣的错误htdocs默认Web⽂档根⽬录,就是存放默认⾸页的位置icons Apache预设的⼀些⼩图标存放⽬录includeliblogs Apache ⽇志⽂件存放⽬录,主要包括访问⽇志 access.log 和错误⽇志 error.logmodules Apache服务器⽀持的动态加载模块所在⽬录安装 Aapche 服务使⽤管理员⾝份运⾏cmd,命令⾏下进⼊到 Apache 下⾯的 bin ⽬录,输⼊httpd -k install把apache安装成windows后台服务。
命令启动Apache服务:httpd -k starthttpd -k stop停⽌httpd -k restart重启更多命令,请使⽤httpd -help查看如果出现以下错误【原因】httpd.conf ⾥⾯配置的 ServerRoot 路径跟实际路径不⼀致,导致路径⽆效。
【解决⽅案】修改 D:\httpd\Apache24\conf ⽬录下的 httpd.conf ⽂件,在38⾏左右Define SRVROOT "D:/httpd/Apache24"ServerRoot "${SRVROOT}"注意路径是 “/”不是“\”端⼝冲突问题Apache 默认使⽤的端⼝号为 80,如果遇到 80 端⼝被其他应⽤程序占⽤的情况,有两种解决⽅案:⽅案⼀:将占⽤ 80 端⼝的程序关闭掉,具体做法如下:在cmd中运⾏netstat -ano "80"查看是哪个PID在使⽤ 80 端⼝,查找到PID 后可以使⽤ kill 命令将其结束掉进程。
Linux——搭建Apache(httpd)服务器⼀、基本概念Apache(或httpd)是Internet上使⽤最多的Web服务器技术之⼀,使⽤的传输协议是http超⽂本传输协议(⼀个基于超⽂本的协议),⽤于通过⽹络连接来发送和接受对象。
有两个版本:http:超⽂本传输协议,通过线路以明⽂形式发送,默认情况下使⽤80/TCP(也可以使⽤其他端⼝)https:经TLS/SSL安全加密的超⽂本传输协议,默认情况下使⽤端⼝443/TCP⼆、了解Apache的配置⽂件1、配置⽂件的分类在Linux系统中配置服务,其实就是修改服务的配置⽂件,httpd服务程序的主要配置⽂件及存放位置如下:配置⽂件的名称存放位置服务⽬录/etc/httpd主配置⽂件/etc/httpd/conf/httpd.conf虚拟主机配置⽂件/etc/httpd/conf.d⽇志⽂件/etc/httpd/logs⽹站数据⽬录/var/www/html2、主配置⽂件的重要参数主配置⽂件/etc/httpd/conf/httpd.conf参数⽤途ServerRoot服务⽬录ServerAdmin管理员邮箱User运⾏服务的⽤户Group运⾏服务的⽤户组ServerName⽹站服务器的域名DocumentRoot⽂档根⽬录(⽹站数据⽬录)Directory⽹站数据⽬录的权限Listen监听的IP地址与端⼝号DirectoryIndex默认的索引页页⾯ErrorLog错误⽇志⽂件CustomLog访问⽇志⽂件Timeout⽹页超时时间,默认为300秒3、Directory标签<Directory "/var/www/html">AllowOverride None #设置.htaccess⽂件中的指令类型,None表⽰禁⽌使⽤.htaccess,该参数⼀般不改Require all granted #设置权限,默认开启所有客户机访问权限</Directory>三、如何配置Apache服务器⾸先准备:主机名、⽹络、yum源1、更改主机名:[root@localhost ~]# hostnamectl set-hostname $主机名[root@localhost ~]# bash #环境变量重载2、配置⽹络(1)虚拟交换机、⽹络适配器选择仅主机模式,并且配置为192.168.100.0⽹段;(2)编辑⽹络配置⽂件:[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33修改: BOOTPROTO=static #改为静态IP地址ONBOOT=yes #改为开机⾃启IPADDR=192.168.100.10PREFIX=24 或者 NETMASK=255.255.255.0(3)重启⽹络服务:[root@localhost ~]# systemctl restart network3、配置yum源(1)先在VMware⾥⾯把系统镜像⽂件连接到虚拟机的光驱上;(2)挂载光驱⾥的镜像:[root@localhost ~]# mount /dev/cdrom /media(3)修改yum源配置⽂件:[root@localhost ~]# vim /etc/yum.repos.d/local.repo[rhel]name=rhelbaseurl=file:///mediaenabled=1gpgcheck=0(4)清空yum源缓存信息:[root@localhost ~]# yum clean all(5)检索当前yum源信息:[root@localhost ~]# yum repolist任务⼀:配置简单的httpd服务1、安装httpd服务[root@server ~]# yum -y install httpd2、启动httpd服务[root@server ~]# systemctl restart httpd[root@server ~]# systemctl enable httpd3、配置防⽕墙[root@server ~]# firewall-cmd --permanent --add-service=http[root@server ~]# firewall-cmd --reload4、关闭SELinux[root@server ~]# setenforce 05、客户端测试[root@client ~]# firefox http://IP地址或者 curl http://IP地址任务⼆:配置基于⽤户的个⼈⽹站注意:该⽤户必须在Linux系统中存在1、新建⼀个⽤户(⽹站基于该⽤户)[root@server ~]# useradd user0[root@server ~]# passwd user02、修改⽤户的家⽬录权限,使其他⽤户具有读取和执⾏的权限[root@server ~]# chmod -R 705 /home/user03、创建存放⽤户个⼈主页空间的⽬录,写user0的⽹页⽂件[root@server ~]# mkdir /home/user0/public_html[root@server ~]# cd /home/user0/public_html[root@server ~]# echo "this is user0's web">>index.html4、修改基于⽤户的httpd配置⽂件[root@server ~]# vim /etc/httpd/conf.d/userdir.conf修改: UserDir enabled #开启,表⽰让httpd服务程序开启个⼈⽤户主页功能UserDir public_html #去注释,UserDir参数表⽰⽹站数据在⽤户家⽬录中的保存⽬录名称5、配置防⽕墙(同上)[root@server ~]# firewall-cmd --permanent --add-service=http[root@server ~]# firewall-cmd --reload6、修改selinux权限[root@server ~]# getsebool -a|grep home[root@server ~]# setsebool httpd_enable_homedirs on7、重启服务[root@server ~]# systemctl restart httpd8、客户端测试[root@client ~]# firefox http://IP地址/~username 或者curl http://IP地址/~username任务三:配置基于域名访问的虚拟主机1、新建虚拟主机的⽹页⽂件[root@server ~]# mkdir /www/one /www/two[root@server ~]# cd /www/one[root@server ~]# echo "this is a web for virtual host one">>index.html[root@server ~]# cd /www/two[root@server ~]# echo "this is a web for virtual host two">>index.html[root@server ~]# chmod o+x /www2、配置虚拟主机的⽂件[root@server ~]# cd /etc/httpd/conf.d[root@server ~]# vim vhost.conf<Directory /www/one> #设置⽹站⽬录权限Require all granted #开启所有客户机访问权限</Directory><VirtualHost 192.168.100.10> #虚拟主机ServerName #定义服务器名称DocumentRoot /www/one/ #⽹站数据⽬录</VirtualHost><Directory /www/two>Require all granted</Directory><VirtualHost 192.168.100.11>ServerName DocumentRoot /www/two/</VirtualHost>3、做域名解析⽂件server/client[root@server ~]# vim /etc/hosts192.168.100.10 192.168.100.11 4、配置防⽕墙(同上)[root@server ~]# firewall-cmd --permanent --add-service=http[root@server ~]# firewall-cmd --reload5、修改虚拟主机⽹页⽂件的selinux上下⽂类型[root@server ~]# semanage fcontext -a -t httpd_sys_content_t '/www(/.*)?'[root@server ~]# restorecon -RFv /www6、重启服务[root@server ~]# systemctl restart httpd任务四:配置基于端⼝访问的虚拟主机1——新建虚拟主机的⽹页⽂件[root@server ~]# mkdir /www/8088[root@server ~]# echo "this is a web for port 8088 ">>index.html[root@server ~]# mkdir /www/8089[root@server ~]# echo "this is a web for port 8089 ">>index.html2——配置虚拟主机的⽂件[root@server ~]# cd /etc/httpd/conf.d[root@server ~]# vim vhost.conf<Directory /www/8088/>Require all granted</Directory><virtualHost 192.168.100.10:8088>DocumentRoot /www/8088/</virtualHost><Directory /www/8089/>Require all granted</Directory><virtualHost 192.168.100.10:8089>DocumentRoot /www/8089/</virtualHost>3、配置防⽕墙[root@server ~]# firewall-cmd --permanent --zone=public --add-port=8089/tcp[root@server ~]# firewall-cmd --permanent --zone=public --add-port=8088/tcp[root@server ~]# firewall-cmd --reload4、关闭SELinux[root@server ~]# setenforce 05、重启服务[root@server ~]# systemctl restart httpd6、使⽤浏览器访问任务五:配置基于TLS加密的虚拟主机注意:经TLS/SSL安全加密的超⽂本传输协议,默认情况下使⽤端⼝443/TCP 1、安装TLS加密软件,⽹站内容不⽤明⽂传输[root@server ~]# yum -y install mod_ssl2、⽣成密钥[root@server ~]# openssl genrsa >tlsweb.key3、⽣成证书请求⽂件[root@server ~]# openssl req -new -key tlsweb.key > tlsweb.csr4、⽣成证书⽂件[root@server ~]# openssl req -x509 -days 365 -key tlsweb.key -in tlsweb.csr >tlsweb.crt5、修改ssl.conf配置⽂件[root@server ~]# vim /etc/httpd/conf.d/ssl.confSSLCertificateFile /etc/pki/tls/certs/tlsweb.crtSSLCertificateKeyFile /etc/pki/tls/private/tlsweb.key6、把证书⽂件拷贝到ssl.conf配置⽂件⾥的对应路径下⾯[root@server ~]# cp tlsweb.crt /etc/pki/tls/certs/7、把秘钥⽂件拷贝到ssl.conf配置⽂件⾥的对应路径下⾯[root@server ~]# cp tlsweb.key /etc/pki/tls/private/。
ApachehttpServer2.4安装与配置前⾔Apache官⽹从2.2之后,不再提供windows的msi或exe安装版本,现在Apache http Server有两个分⽀2.2及2.4注意事项如果之前有安装2.2的版本,请先卸载Apache2.4下载2、选择2.4的版本,点击 (windows安装版本)3、选择前三个⽹站中的任意⼀下进⼊下载,(推荐Apache Lounge镜像站点快)4、以为例,选择需要的x86或x64进⾏下载注意事项不同的VC对应不同的vc++(简单理解为Visual Studio)版本,我的电脑上安装了VS2015所以选择VC14,如果是vs2012请选择VC11我的环境我的电脑安装了VS2015,WIN10 X64位操作系统⽂件分析解压⽂件1、下载完成后,解压出⽬录如下:2、详细的安装配置步骤可以参考图⼀中的ReadMe.txt主要的⽂件和⽬录创建服务:bin\httpd.exe管理⾯板:bin\ApacheMonitor.exe主要的配置⽂件:conf\httpd.conf⽹站根⽬录:\htdocs配置⽅法下⾯说⼀下我的简单配置步骤1、默认的安装⽬录是在C:/Apache24,找到⾃⼰的实际⽬录⽐如我的D:/Apache242、打开conf\httpd.conf把⽂件中的所有 ”c:/Apache24″替换为⾃⼰的安装⽬录,如” d:/Apache24″找到 218⾏(版本不同,可能有区别)的 ServerName ,把前⾯的 # 去掉找到 DocumentRoot ,修改⽹站的根⽬录,⽐如是 “d:/Apache24/htdocs”DocumentRoot 下⽅⼀⾏的 Directory也做相应修改修改端⼝号——“Listen:80”改为80803、以管理员⾝份运⾏CMD,进⼊Apache24\bin ⽬录(httpd.exe所在⽬录)4、输⼊ httpd.exe -k install -n "Apache24" 安装服务(注:Apache24为安装服务名称)安装完成5、⾄此,安装基本完成。
Apache是一个历史悠久并且功能十分强大的WEB服务器,但其丰富的功能对于一个新手来说往往不知道从何下手。
我个人感觉Apache的设计充分体现了模块化设计的优势,通过在动态模块加载(DSO)模式下的安装,任何子应用模块都可以通过配置文件的简单修改进行积木式的灵活配置。
安装的过程可以从简单的静态html服务开始,一个模块一个模块的学习使用。
从单纯的HTML静态服务(core),到复杂的动态页面服务(core + php, core + resin, core + php + mod_gzip, core + resin + mod_expire)。
本文主要从简化安装==>性能调优==>维护方便的角度,介绍了WEB服务的规划、HTTPD安装/应用模块配置、升级/维护等过程。
让Apache和PHP,Resin等应用模块的独立升级,完全互不影响。
1.WEB应用容量规划:根据硬件配置和WEB应用的特点进行WEB服务的规划及一些简单的估算公式;2.Apache安装过程:apache的通用的简化安装选项,方便以后的应用的模块化配置;修改 HARD_SERVER_LIMIT:vi /path/to/apache_src/src/include/httpd.h#define HARD_SERVER_LIMIT 2560 <===将原来的 HARD_SERVER_LIMIT 256 后面加个“0”apache编译:./configure --prefix=/home/apache --enable-shared=max --enable-module=most3.可选应用模块/工具的安装:php resin mod_gzip mod_expire及各个模块之间的配合;mod_php安装:./configure --with-apxs=/home/apache/bin/apxs --enable-track-vars --with-mysqlmod_resin安装:./configure --with-apxs=/home/apache/bin/apxsmod_gzip安装:修改Makefile中的 apxs路径:然后make make install工具:日志轮循工具cronolog安装:4.升级/维护:看看通用和模块化的安装过程如何简化了日常的升级/维护工作;按照以上的方法:系统管理员和应用管理员的职责可以清楚的分开,互相独立。
httpd.conf配置完美详解Linux下httpd.conf 配置详解1. 关于本文本文将以Apache 2.2为例,以rhel5为平台,讲述Apache服务器的安装和设置。
2. 关于ApacheApache 是一款功能强大、稳定、可支撑关键任务的Web服务器Apache具有如下特性:1) 几乎可以运行在所有的计算机平台上.2) 支持最新的HTTP/1.1协议3) 简单而且强有力的基于文件的配置(HTTPD.CONF).4) 支持通用网关接口(CGI)5) 支持虚拟主机.6) 支持HTTP认证.7) 集成PERL.8) 集成的代理服务器9) 可以通过WEB浏览器监视服务器的状态, 可以自定义日志.10) 支持服务器端包含命令(SSI).11) 支持安全SOCKET层(SSL).12) 具有用户会话过程的跟踪能力.13) 支持FASTCGI14) 支持JAVA SERVLETS.……更多信息请参阅Apache网站:/doc/327020310.html,3. Apache的安装Apache的安装无外两种方式:源码包安装和二进制包安装。
这两种方式各有特色,二位制包安装不需编译,针对不同的平台有经过优化编译的不同的二进制文件以及包格式,安装简单方便,源码包则必须先配置编译再安装,可以根据你所用的主机环境进行优化、选择你所用的模块,安装定制更灵活。
下面分别介绍这两种安装方式。
3.1 以源码包方式安装3.1.1 下载最新版本的apache软件访问apahce网站/doc/327020310.html,/download.cgi下载最新版本的Apache源码包。
本文使用的是2.2.6版本,在linux系统下用下面的命令下载:wget /doc/327020310.html,/httpd/httpd-2.2.6.tar.gz3.1.2 解压缩下载的源码包首先建立一个工作目录( 笔者建议的目录为/usr/local/src/apache ) :mkdir -p /usr/local/src/apache 将下载的源码包移至工作目录:mv httpd-2.2.6.tar.gz /usr/local/src/apache进入工作目录并用tar命令解压源码包:cd /usr/local/src/apachetar zxvf httpd-2.2.6.tar.gz命令执行结束后,当前工作目录下将生成一个新的子目录httpd-2.2.6,此目录下即为Apache的源码文件。
下面是linux下安装apache的完整代码,系统是redhat5.51、检查系统防火墙有没开,需要把防火墙关掉,可以执行SETUP查看,关闭。
在开启了防火墙时,做如下设置,开启相关端口,修改/etc/sysconfig/iptables 文件,添加以下内容:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 8088 -j ACCEPT 2、安装Apache下载地址:</>1. 安装Apache# tar zxvf httpd-2.2.22.tar.gz //解压文件# cd httpd-2.2.22//进入安装文件夹#./configure --prefix=/usr/local/apache --enable-so--enable-mods-shared=most --enable-proxy --enable-proxy-connect--enable-proxy-ftp --enable-proxy-http --enable-proxy-scgi--enable-proxy-ajp --enable-proxy-balancer // 配置apache路径加载动态模块# make //编译apache# make install//安装apache其它相关命令:下载httpd-2.2.22.tar.bz2 把httpd-2.2.22.tar.bz2放到/soft 下[root@localhost ~]#cd /soft[root@localhost soft]#tar jxvf httpd-2.2.6.tar.bz2 //解压apache的压缩包[root@localhost soft]#cd httpd-2.2.6 //定位到httpd-2.2.6 文件夹下[root@localhost httpd-2.2.6]#ls //查看显示httpd-2.2.6 文件夹下内容 [root@localhost httpd-2.2.6]# ./configure --help | more //查看安装apache配置参数[root@localhost httpd-2.2.6]#./configure --prefix=/usr/local/apache --enable-so // 配置apache路径[root@localhost httpd-2.2.6]#./configure --prefix=/usr/local/apache--enable-so --enable-mods-shared=most --enable-proxy--enable-proxy-connect --enable-proxy-ftp --enable-proxy-http--enable-proxy-scgi --enable-proxy-ajp --enable-proxy-balancer// 配置apache路径加载动态模块[root@localhost httpd-2.2.6]#make //编译apache[root@localhost httpd-2.2.6]#make install //安装apache[root@localhost httpd-2.2.6]#cd /usr/local/apache //进入apache的目录[root@localhost apache]# cd conf/[root@localhost conf]#cp httpd.conf httpd.conf_bak //备份apache配置文件[root@localhost conf]#chkconfig --list httpd //查看httpd服务是否已存在[root@localhost conf]#chkconfig httpd off //关闭系统自带了httpd的服务,如果存在httpd服务[root@localhost conf]#service httpd status //查看自带httpd服务状态[root@localhost conf]# /usr/local/apache/bin/apachectl -k start//linux启动apache命令[root@localhost conf]# /usr/local/apache/bin/apachectl -k stop //linux 停止apache命令[root@localhost conf]#netstat -an | grep :80 //查看linux80端口是否开启[root@localhost conf]#ps -aux | grep httpd //linux下查看apache进程[root@localhost conf]#cd ../..[root@localhost local]#cp /usr/local/apache/bin/apachectl/etc/rc.d/init.d/apache //拷贝apache启动脚本[root@localhost local]#vi /etc/rc.d/init.d/apache // 这里是编辑apache 启动脚本在开头的#!/bin/sh 下面加上#chkconfig: 2345 85 15[root@localhost local]#chkconfig --add apache //添加apache服务[root@localhost local]#chkconfig --list apache //列出apache服务[root@localhost local]#service apache stop //停止apache服务[root@localhost local]#netstat -an | grep :80 //查看linux的80端口是否开启[root@localhost local]#ps -aux | grep httpd //查看是否存在httpd服务,若果之前自带httpd服务启动的话会导致新添加的apache服务启动失败[root@localhost local]#service apache start //启动apache服务打开你的服务器ip地址,看看是否出现了tomcat的默认首页,如果出现的话,那么恭喜你linux下安装apache已经成功了3、修改httpd.conf文件vi /usr/local/apache/conf/httpd.conf以下为httpd.conf内容:# This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions.# See <URL:/docs/2.2> for detailed information.# In particular, see# <URL:/docs/2.2/mod/directives.html># for a discussion of each configuration directive.## Do NOT simply read the instructions in here without understanding# what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned.## Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so "logs/foo_log"# with ServerRoot set to "/usr/local/apache" will be interpreted by the # server as "/usr/local/apache/logs/foo_log".## ServerRoot: The top of the directory tree under which the server's# configuration, error, and log files are kept.## Do not add a slash at the end of the directory path. If you point# ServerRoot at a non-local disk, be sure to point the LockFile directive # at a local disk. If you wish to share the same ServerRoot for multiple # httpd daemons, you will need to change at least LockFile and PidFile. #ServerRoot "/usr/local/apache"## Listen: Allows you to bind Apache to specific IP addresses and/or# ports, instead of the default. See also the <VirtualHost># directive.## Change this to Listen on specific IP addresses as shown below to# prevent Apache from glomming onto all bound IP addresses.##Listen 12.34.56.78:80Listen 80Listen 8088 --增加监听端口## Dynamic Shared Object (DSO) Support## To be able to use the functionality of a module which was built as a DSO you# have to place corresponding `LoadModule' lines at this location so the # directives contained in it are actually available _before_ they are used.# Statically compiled modules (those listed by `httpd -l') do not need# to be loaded here.## Example:# LoadModule foo_module modules/mod_foo.so#LoadModule authn_file_module modules/mod_authn_file.so --加载的模块,正确安装完会自动加载以下模块LoadModule authn_dbm_module modules/mod_authn_dbm.soLoadModule authn_anon_module modules/mod_authn_anon.soLoadModule authn_dbd_module modules/mod_authn_dbd.soLoadModule authn_default_module modules/mod_authn_default.soLoadModule authz_host_module modules/mod_authz_host.soLoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_user_module modules/mod_authz_user.soLoadModule authz_dbm_module modules/mod_authz_dbm.soLoadModule authz_owner_module modules/mod_authz_owner.soLoadModule authz_default_module modules/mod_authz_default.soLoadModule auth_basic_module modules/mod_auth_basic.soLoadModule auth_digest_module modules/mod_auth_digest.soLoadModule dbd_module modules/mod_dbd.soLoadModule dumpio_module modules/mod_dumpio.soLoadModule reqtimeout_module modules/mod_reqtimeout.soLoadModule ext_filter_module modules/mod_ext_filter.soLoadModule include_module modules/mod_include.soLoadModule filter_module modules/mod_filter.soLoadModule substitute_module modules/mod_substitute.soLoadModule deflate_module modules/mod_deflate.soLoadModule log_config_module modules/mod_log_config.soLoadModule logio_module modules/mod_logio.soLoadModule env_module modules/mod_env.soLoadModule expires_module modules/mod_expires.soLoadModule headers_module modules/mod_headers.soLoadModule ident_module modules/mod_ident.soLoadModule setenvif_module modules/mod_setenvif.soLoadModule version_module modules/mod_version.soLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_connect_module modules/mod_proxy_connect.soLoadModule proxy_ftp_module modules/mod_proxy_ftp.soLoadModule proxy_http_module modules/mod_proxy_http.soLoadModule proxy_scgi_module modules/mod_proxy_scgi.soLoadModule proxy_ajp_module modules/mod_proxy_ajp.soLoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule mime_module modules/mod_mime.soLoadModule dav_module modules/mod_dav.soLoadModule status_module modules/mod_status.soLoadModule autoindex_module modules/mod_autoindex.soLoadModule asis_module modules/mod_asis.soLoadModule info_module modules/mod_info.soLoadModule cgi_module modules/mod_cgi.soLoadModule dav_fs_module modules/mod_dav_fs.soLoadModule vhost_alias_module modules/mod_vhost_alias.soLoadModule negotiation_module modules/mod_negotiation.soLoadModule dir_module modules/mod_dir.soLoadModule imagemap_module modules/mod_imagemap.soLoadModule actions_module modules/mod_actions.soLoadModule speling_module modules/mod_speling.soLoadModule userdir_module modules/mod_userdir.soLoadModule alias_module modules/mod_alias.soLoadModule rewrite_module modules/mod_rewrite.soTimeout 300 --新增的配置参数KeepAlive OnMaxKeepAliveRequests 1000KeepAliveTimeout 15UseCanonicalName OffAccessFileName .htaccessServerTokens FullServerSignature OnHostnameLookups Off<IfModule !mpm_netware_module><IfModule !mpm_winnt_module>## If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch.## User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services.#User daemonGroup daemon</IfModule></IfModule>----------------------------------以下内容是新增的关键参数<IfModule mpm_prefork_module>StartServers 40MinSpareServers 40MaxSpareServers 80MaxClients 256MaxRequestsPerChild 10000</IfModule><IfModule mpm_worker_module>StartServers 40MaxClients 2000MinSpareThreads 100MaxSpareThreads 300ThreadsPerChild 200MaxRequestsPerChild 0</IfModule>ProxyRequests OffRewriteEngine onRewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)RewriteRule .* - [F]RewriteEngine onRewriteCond %{HTTP:range} !(^bytes=[^,]+(,[^,]+){0,4}$|^$)RewriteRule .* - [F]TraceEnable off#NameVirtualHost 10.46.85.137:9080#<VirtualHost 10.46.85.137:9080>#ServerName 10.46.85.137:9080#ProxyPass /ponApp/ http://10.209.122.40:7001/xponApp/#ProxyPassReverse /ponApp/ http://10.209.122.40:7001/xponApp/#</VirtualHost>NameVirtualHost 10.46.85.137:8088<VirtualHost 10.46.85.137:8088>ServerName kuangdai --kuangdai LINUX系统的主机名ProxyPass /xponApp/ http://10.209.122.40:7001/xponApp/ ProxyPassReverse /xponApp/ http://10.209.122.40:7001/xponApp/启动服务报错--/etc/hosts 增加127.0.0.1 localhost.localdomainlocalhost ”kuangdai“主机名</VirtualHost><Proxy *>--配置反向代理的访问权限Order deny,allowAllow from all</Proxy>-----------------------------以上内容是新增的关键参数# 'Main' server configuration## The directives in this section set up the values used by the 'main'# server, which responds to any requests that aren't handled by a# <VirtualHost> definition. These values also provide defaults for# any <VirtualHost> containers you may define later in the file.## All of these directives may appear inside <VirtualHost> containers,# in which case these default settings will be overridden for the# virtual host being defined.### ServerAdmin: Your address, where problems with the server should be# e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. admin@#ServerAdmin you@## ServerName gives the name and port that the server uses to identify itself.# This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup.## If your host doesn't have a registered DNS name, enter its IP address here. #ServerName 127.0.0.1:80 --这个ServerName可随意配置一定去掉前面### DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations.#DocumentRoot "/usr/local/apache/htdocs"## Each directory to which Apache has access can be configured with respect # to which services and features are allowed and/or disabled in that# directory (and its subdirectories).## First, we configure the "default" to be a very restrictive set of# features.#<Directory />Options FollowSymLinksAllowOverride NoneOrder deny,allowDeny from all</Directory>## Note that from this point forward you must specifically allow# particular features to be enabled - so if something's not working as # you might expect, make sure that you have specifically enabled it# below.### This should be changed to whatever you set DocumentRoot to.#<Directory "/usr/local/apache/htdocs">## Possible values for the Options directive are "None", "All",# or any combination of:# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews## Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you.## The Options directive is both complicated and important. Please see # /docs/2.2/mod/core.html#options# for more information.#Options Indexes FollowSymLinks## AllowOverride controls what directives may be placed in .htaccess files.# It can be "All", "None", or any combination of the keywords:# Options FileInfo AuthConfig Limit#AllowOverride None## Controls who can get stuff from this server.#Order allow,denyAllow from all</Directory>## DirectoryIndex: sets the file that Apache will serve if a directory# is requested.#<IfModule dir_module>DirectoryIndex index.html</IfModule>## The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients.#<FilesMatch "^\.ht">Order allow,denyDeny from allSatisfy All</FilesMatch>## ErrorLog: The location of the error log file.# If you do not specify an ErrorLog directive within a <VirtualHost># container, error messages relating to that virtual host will be# logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here.#ErrorLog "logs/error_log"## LogLevel: Control the number of messages logged to the error_log.# Possible values include: debug, info, notice, warn, error, crit,# alert, emerg.#LogLevel warn<IfModule log_config_module>## The following directives define some format nicknames for use with # a CustomLog directive (see below).#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" common<IfModule logio_module># You need to enable mod_logio.c to use %I and %OLogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"\"%{User-Agent}i\" %I %O" combinedio</IfModule>## The location and format of the access logfile (Common Logfile Format). # If you do not define any access logfiles within a <VirtualHost># container, they will be logged here. Contrariwise, if you *do*# define per-<VirtualHost> access logfiles, transactions will be# logged therein and *not* in this file.#CustomLog "logs/access_log" common## If you prefer a logfile with access, agent, and referer information # (Combined Logfile Format) you can use the following directive.##CustomLog "logs/access_log" combined</IfModule><IfModule alias_module>## Redirect: Allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. The client # will make a new request for the document at its new location.# Example:# Redirect permanent /foo /bar## Alias: Maps web paths into filesystem paths and is used to# access content that does not live under the DocumentRoot.# Example:# Alias /webpath /full/filesystem/path## If you include a trailing / on /webpath then the server will# require it to be present in the URL. You will also likely# need to provide a <Directory> section to allow access to# the filesystem path.## ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that# documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. The same rules about trailing "/" apply to ScriptAlias# directives as to Alias.#ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"</IfModule><IfModule cgid_module>## ScriptSock: On threaded servers, designate the path to the UNIX# socket used to communicate with the CGI daemon of mod_cgid.##Scriptsock logs/cgisock</IfModule>## "/usr/local/apache/cgi-bin" should be changed to whatever your ScriptAliased# CGI directory exists, if you have that configured.#<Directory "/usr/local/apache/cgi-bin">AllowOverride NoneOptions NoneOrder allow,denyAllow from all</Directory>## DefaultType: the default MIME type the server will use for a document # if it cannot otherwise determine one, such as from filename extensions. # If your server contains mostly text or HTML documents, "text/plain" is # a good value. If most of your content is binary, such as applications # or images, you may want to use "application/octet-stream" instead to # keep browsers from trying to display binary files as though they are # text.#DefaultType text/plain<IfModule mime_module>## TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type.#TypesConfig conf/mime.types## AddType allows you to add to or override the MIME configuration# file specified in TypesConfig for specific file types.##AddType application/x-gzip .tgz## AddEncoding allows you to have certain browsers uncompress# information on the fly. Note: Not all browsers support this.##AddEncoding x-compress .Z#AddEncoding x-gzip .gz .tgz## If the AddEncoding directives above are commented-out, then you# probably should define those extensions to indicate media types: #AddType application/x-compress .ZAddType application/x-gzip .gz .tgz## AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below)## To use CGI scripts outside of ScriptAliased directories:# (You will also need to add "ExecCGI" to the "Options" directive.) ##AddHandler cgi-script .cgi# For type maps (negotiated resources):#AddHandler type-map var## Filters allow you to process content before it is sent to the client. ## To parse .shtml files for server-side includes (SSI):# (You will also need to add "Includes" to the "Options" directive.) ##AddType text/html .shtml#AddOutputFilter INCLUDES .shtml</IfModule>## The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located.##MIMEMagicFile conf/magic## Customizable error responses come in three flavors:# 1) plain text 2) local redirects 3) external redirects## Some examples:#ErrorDocument 500 "The server made a boo boo."#ErrorDocument 404 /missing.html#ErrorDocument 404 "/cgi-bin/missing_handler.pl"#ErrorDocument 402 /subscription_info.html### MaxRanges: Maximum number of Ranges in a request before# returning the entire resource, or one of the special# values 'default', 'none' or 'unlimited'.# Default setting is to accept 200 Ranges.#MaxRanges unlimited## EnableMMAP and EnableSendfile: On systems that support it,# memory-mapping or the sendfile syscall is used to deliver# files. This usually improves server performance, but must# be turned off when serving from networked-mounted# filesystems or if support for these functions is otherwise# broken on your system.##EnableMMAP off#EnableSendfile off# Supplemental configuration## The configuration files in the conf/extra/ directory can be# included to add extra features or to modify the default configuration of # the server, or you may simply copy their contents here and change as# necessary.# Server-pool management (MPM specific)#Include conf/extra/httpd-mpm.conf# Multi-language error messages#Include conf/extra/httpd-multilang-errordoc.conf# Fancy directory listings#Include conf/extra/httpd-autoindex.conf# Language settings#Include conf/extra/httpd-languages.conf# User home directories#Include conf/extra/httpd-userdir.conf# Real-time info on requests and configuration#Include conf/extra/httpd-info.conf# Virtual hosts#Include conf/extra/httpd-vhosts.conf# Local access to the Apache HTTP Server Manual#Include conf/extra/httpd-manual.conf# Distributed authoring and versioning (WebDAV)#Include conf/extra/httpd-dav.conf# Various default settings#Include conf/extra/httpd-default.conf# Secure (SSL/TLS) connections#Include conf/extra/httpd-ssl.conf## Note: The following must must be present to support# starting without SSL on platforms with no /dev/random equivalent # but a statically compiled-in mod_ssl.#<IfModule ssl_module>SSLRandomSeed startup builtinSSLRandomSeed connect builtin </IfModule>。
Apache服务器的安装与配置
一、安装Apache
双击可执行文件apache_1.3.33-win32-x86-no_src.exe,将Apache服务器软件安装至C:\Apache目录下。
二、设置C:\apache\conf\httpd.donf文件
修改Apache的核心配置文件c:\apache\conf\httpd.conf(说明一点:“#”为Apache的注释符号)。
修改方法如下:
1、寻找到ServerName。
这里定义你的域名。
这样,当Apache Server运行时,你可以在浏览器中访问自己的站点。
如果前面有#,记得删除它。
2、寻找到ServerAdmin。
这里输入你的E-Mail地址。
(以上两条在安装时应该已经配置好了,所以不必改动,这里介绍一下,主要是为了日后的修改)
3、寻找到。
向下有一句Options,去掉后面所有的参数,加一个All(注意区分大小写!A 大写,两个l小写。
下同。
);接着还有一句Allow Override,也同样去掉后面所有的参数,加一个All。
<Directory "C:/Program Files/Apache Group/Apache/cgi-bin">
AllowOverride All
Options All
Order allow,deny
Allow from all
</Directory>
4、寻找到DocumentRoot。
这个语句指定你的网站路径,也就是你主页放置的目录。
你可以使用默认的,也可以自己指定一个,但记住,这句末尾不要加“/”。
此外注意,路径的分隔符在Apache Server里写成“/”。
(将DocumentRoot "C:/apache/htdocs"改为DocumentRoot "C:/try")
5、寻找到DirectoryIndex。
这就是你站点第一个显示的主页,在index.html的后面加入index.htm index.php index.php3 index.cgi index.pl。
注意,每种类型之间都要留一空格!这里添加好了,以后就不用再麻烦了。
6、port(端口号),如果没安装IIS的话,就保持80不要变,否则,就要改一下(因为IIS的WEB服务占据了80),可以改成81等等。
三、Apache的手动启动和停止
Net start apache启动apache服务,Net stop apache停止apache服务。
在windows2000里,net 命令是用途相当广泛的。
其中net start 用来启动服务程序,而net stop 用来关闭服务。
在修改了apache的配置参数,需要先停止apache服务后再重新启动。
这样修改后的配置才能生效。
C:\>net start apache
Apache 服务正在启动.
Apache 服务已经启动成功。
C:\>net stop apache
Apache 服务正在停止.
Apache 服务已成功停止。
这时Apache已经启动了,可以在IE地址栏里输入:http://localhost/或http://127.0.0.1看看。
在“管理工具”的“服务”项中,也可以找到Apache服务了,以后Apache就可以作为一项Windows2000服务,随着机器的启动而运行了!。