apache配置大全.docx
- 文档编号:4266995
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:15
- 大小:18.89KB
apache配置大全.docx
《apache配置大全.docx》由会员分享,可在线阅读,更多相关《apache配置大全.docx(15页珍藏版)》请在冰豆网上搜索。
apache配置大全
apache:
apatchyserver
http超文本传输协议
常见的web服务器:
(1)apache
(2)nginx
(3)lighttd
-------------------
apache的优点:
(1)开源,免费
(2)支持模块控制
(3)支持虚拟主机
(4)支持进程控制
------------------
具体配置:
httpd
[root@t1named]#yumsearchhttpd
Loadedplugins:
rhnplugin,security
ThissystemisnotregisteredwithRHN.
RHNsupportwillbedisabled.
base|1.3kB00:
00
========================Matched:
httpd========================
mod_ssl.i386:
SSL/TLSmodulefortheApacheHTTPserver
system-config-httpd.noarch:
Apacheconfigurationtool
httpd.i386:
ApacheHTTPServer
httpd-devel.i386:
DevelopmenttoolsfortheApacheHTTPserver.
httpd-manual.i386:
DocumentationfortheApacheHTTPserver.
mod_dav_svn.i386:
ApacheservermoduleforSubversionserver.
1,安装
[root@t1named]#yuminstall-yhttpd
[root@t1etc]#rpm-qlhttpd
/etc/httpd
/etc/httpd/conf.d/proxy_ajp.conf子配置文件
/etc/httpd/conf.d/welcome.conf子配置文件
/etc/httpd/conf/httpd.conf主配置文件
/etc/httpd/logs日志
/etc/httpd/modules模块
/etc/httpd/runpid
/etc/logrotate.d/httpd日志轮滚
/etc/rc.d/init.d/httpd启动脚本
/usr/bin/ab压力测试的命令
/usr/bin/htpasswd
几个相关的问题:
(1)什么是URL?
统一资源定位符
0
(2)网络空间
web服务器上的一个目录
CPU
2,配置
[root@t1~]#cd/etc/httpd/conf
[root@t1conf]#ls
httpd.conf
[root@t1conf]#vimhttpd.conf
57ServerRoot"/etc/httpd"
134Listen80
210Includeconf.d/*.conf
231Userapache
232Groupapache
281DocumentRoot"/var/www/html"**定义默认的页面发布目录
291
292OptionsFollowSymLinks
293AllowOverrideNone
294
这个/是虚拟的,真实的路径是"/var/www/html"
306
320OptionsIndexesFollowSymLinks选项
327AllowOverrideNone是否需要验证
332Orderallow,deny访问控制
333Allowfromall
335
实验:
(1)Indexes支持索引
[root@t1conf]#cd/var/www/html/
[root@t1html]#ls
bj
[root@t1html]#echo"helloall">index.html
[root@t1html]#ls
bjindex.html
为什么会有redhat的欢迎页面?
[root@t1html]#cd/etc/httpd/conf.d/
[root@t1conf.d]#vimwelcome.conf
#
#Options-Indexes
#ErrorDocument403/error/noindex.html
#
[root@t1conf.d]#/etc/init.d/httpdrestart
文本界面访问:
[root@t1conf.d]#elinkshttp:
//172.16.1.2/
图形界面访问:
[root@t1conf.d]#firefoxhttp:
//172.16.1.2/
[root@t1html]#cp/etc/passwd.
[root@t1html]#cp/etc/group.
取消索引功能:
Options-Indexes
(2)FollowSymLinks支持符号链接
在目录下创建一个符号链接:
[root@t1html]#ln-s/etc/fstab.
[root@t1html]#ls-l
lrwxrwxrwx1rootroot10Aug1613:
49fstab->/etc/fstab
取消支持符号链接:
-FollowSymLinks
(3)是否需要验证:
AllowOverrideNone
all开启
none关闭
1)直接在目录容器里编辑:
328authname"hello"验证的名字,任意
329authtypebasic验证的类型,basic-基本验证
330authuserfile"/var/www/html/.htpasswd"验证的时候要读的文件
331requirevalid-user只有保存在文件中的用户才是合法的
[root@t1html]#pwd
/var/www/html
[root@t1html]#htpasswd-c.htpasswda1
Newpassword:
Re-typenewpassword:
Addingpasswordforusera1
[root@t1html]#htpasswd.htpasswda2
Newpassword:
Re-typenewpassword:
Addingpasswordforusera2
[root@t1html]#cat.htpasswd
a1:
w8HEq6Q02CwtY
a2:
oTdxPwX4gUNgI
2)使用其他的文件实现验证
398AccessFileName.htaccess
[root@t1html]#pwd
/var/www/html
[root@t1html]#vim.htaccess
authname"hello"
authtypebasic
authuserfile"/var/www/html/.htpasswd"
requirevalid-user
[root@t1html]#htpasswd-c.htpasswda1
Newpassword:
Re-typenewpassword:
Addingpasswordforusera1
重启服务就可以了。
------------------------------
自定义一个目录容器:
optionsindexes
authname"456"
authtypebasic
authuserfile"/var/www/html/123/.ht"
requirevalid-user
orderallow,deny
allowfromall
---------------------
访问控制:
orderallow,deny
allowfromall
allow允许
deny拒绝
allow,deny:
以allow指定的客户端能够访问,没有允许的全部deny-拒绝访问
deny,allow:
以deny指定的客户端拒绝访问,没有拒绝的客户端allow-都能访问
黑名单:
orderdeny,allow
denyfrom拒绝的客户端
拒绝的客户端:
ip:
172.16.1..2
网段:
172.16.0.0/16
FQDN:
区域:
all
白名单:
orderallow,deny
allowfrom允许的客户端
允许的客户端==拒绝的客户端
例子:
(1)黑名单:
orderdeny,allow
denyfrom127.0.0.1172.16.23.7
只有本机和172.16.23.7不可以访问
(2)白名单
orderallow,deny
allowfrom127.0.0.1172.16.23.7
只有本机和172.16.23.7可以访问
====================================
1xx请求被接受,临时响应
2xx成功
3xx客户端与服务器建立连接的时候,还需要输入一些其他的内容
4xx客户端请求的时候出现错误***
5xx服务器的内部错误***
837Alias/error/"/var/www/error/"
添加目录容器,把错误提示重定向:
optionsindexes
errordocument404/error/404error.html这个文件要自己编辑内容
orderallow,deny
allowfromall
[root@t1error]#pwd
/var/www/error
[root@t1error]#vim404error.html
添加你自定义的错误提示
[root@t1error]#/etc/init.d/httpdrestart
403是没有权限
404是文件找不到
firefoxhttp:
//172.16.1.2/test/234&
[root@t1icons]#pwd
/var/www/icons
把提示由文字变成图片:
optionsindexes
#errordocument404/error/404error.html
errordocument404/icons/world2.png可以自己添加图片,变成错误提示
orderallow,deny
allowfromall
=======================================
用户的个人空间:
#vimhttpd.conf
#UserDirdisable默认是关闭的
UserDirpublic_html开启支持用户的个人空间
optionsindexes
orderallow,deny
allowfromall
[root@t1icons]#useraddu1
[root@t1icons]#cd~u1
[root@t1u1]#pwd
/home/u1
[root@t1u1]#mkdirpublic_html
[root@t1public_html]#vimindex.html
内容自己写
现在配置的有问题,通过查看日志,找出问题?
[root@t1public_html]#cd/var/log/httpd/
[root@t1httpd]#tail-0ferror_log
[FriAug1710:
19:
442012][error][client172.16.1.2](13)Permissiondenied:
accessto/~u1denied
[root@t1u1]#chmodo+x.修改u1家目录的权限,让用户apache能够进入
[root@t1u1]#pwd
/home/u1
[root@t1u1]#ls-ld.
drwx-----x4u1u14096Aug1710:
25.
[root@t1u1]#ls-l
total4
drwxr-xr-x2rootroot4096Aug1710:
14public_html
-rw-rw-r--1u1u10Aug1710:
25u1.f
[root@t1u1]#cdpublic_html/
[root@t1public_html]#ls-l
total4
-rw-r--r--1rootroot9Aug1710:
14index.html
使用别名去掉访问时的~:
alias/u1/"/home/u1/public_html/"
也可以使用软链接
[root@t1public_html]#psaux|grepapache
==================================
虚拟主机:
开启了虚拟主机之后,原来的配置就不好用了。
(1)基于ip的
单网卡多ip
[root@t1u1]#ifconfigeth0:
0172.16.1.4netmask255.255.0.0
[root@t1u1]#mkdir-pv/tmp/{aa,bb}
mkdir:
createddirectory`/tmp/aa'
mkdir:
createddirectory`/tmp/bb'
创建两个目录,作为虚拟主机的documentroot
80> ServerAdminroot@localhost管理员邮箱 DocumentRoot/tmp/aa页面发布目录 ServerNameFQDN ErrorLoglogs/-error_log错误日志 CustomLoglogs/-access_logcommon访问日志 optionsindexes orderallow,deny allowfromall 80> ServerAdminroot@localhost DocumentRoot/tmp/bb ServerName ErrorLoglogs/-error_log CustomLoglogs/-access_logcommon optionsindexes orderallow,deny allowfromall [root@t1u1]#echo"helloaa">/tmp/aa/index.html [root@t1u1]#echo"hellobb">/tmp/bb/index.html 编辑这个文件,代替DNS正向解析: [root@t1u1]#vim/etc/hosts 172.16.1.2 172.16.1.4 测试的结果是: firefox helloaa firefox hellobb (2)基于端口的 使用一个没有被占用的端口vim/etc/service #vimhttpd.conf Listen80 listen889需要声明 80> 内容同上 889> 内容同上 修改DNS的配置: [root@t1u1]#cat/etc/hosts 172.16.1.2 172.16.1.2 测试的结果是: firefox: 80 helloaa firefox: 889 hellobb (3)基于域名的 需要借助DNS: [root@t1httpd]#cd/var/named/chroot/etc/ [root@t1etc]#vimnamed.conf options{ directory"/var/named"; }; zone""{ typemaster; file".zone"; }; zone""{ typemaster; file".zone"; }; [root@t1named]#cd/var/named/chroot/var/named [root@t1named]#cat.zone $TTL86400 @INSOA.root( 42;serial(d.adams) 3H;refresh 15M;retry 1W;expiry 1D);minimum @INNS. nsINA127.0.0.1 wwwINA172.16.1.2 [root@t1named]#cat.zone $TTL86400 @INSOA.root( 42;serial(d.adams) 3H;refresh 15M;retry 1W;expiry 1D);minimum @INNS. nsINA127.0.0.1 wwwINA172.16.1.2 和的ip都解析成你的eth0网卡的ip地址。 [root@t1named]#/etc/init.d/namedrestart 作为DNS的客户端要指向DNS_server [root@t1named]#cat/etc/resolv.conf search nameserver172.16.1.2 #vimhttpd.conf 打开这一行的注释 NameVirtualHost*: 80 80> ServerAdminroot@localhost DocumentRoot/tmp/aa ServerName ErrorLoglogs/-error_log CustomLoglogs/-access_logcommon optionsindexes orderallow,deny allowfromall 80> ServerAdminroot@localhost DocumentRoot/tmp/bb ServerName ErrorLoglogs/-error_log CustomLoglogs/-access_logcommon optionsindexes orderallow,deny allowfromall 测试的结果是: firefox helloaa firefox hellobb ------------------------------------- cgi: 通用网关接口 apache,只能发布静态页面 cgi fastcgi [root@t1cgi-bin]#vimaa.cgi #! /bin/bash echo"Content-type: text/html" echo"" echo"" echo" echo"" [root@t1cgi-bin]#chmod+xaa.cgi 访问: firefoxhttp: //172.16.1.2/cgi-bin/aa.cgi helloall ------------------------------------------------ 压力测试的命令: ab 注意一点,测试的时候不要使用FQDN。 [root@t1cgi-bin]#ab-n1000-c1000http: //172.16.1.2/ Timetakenfortests: 13.806531seconds本次测试花费的时间 Totaltransferred: 1754000bytes本次测试的总的网络流量 Requestspersecond: 72.43[#/sec](mean)吞吐量 Timeperrequest: 13
"
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- apache 配置 大全