httpd配置做业.mmlinux
这几天为了给重要新找工做做最后一些的准备,要整一张网页发布在网上。因为换了新的工做站,要从新安装和配置apache,用来测试。简单从旧机器尝试恢复后,发现了如下的问题,访问报无权限:web
You don't have permission to access /index on this servershell
捣鼓了一下,从中发现对其中不少认识都比较粗浅;例如错误提示中,“我没有访问权限”的“我”是谁?对配置文件中< Directory>配置参数也是只知其一;不知其二。我下意识知道,权限策略至少出如今两层,第一层服务器的用户管理;第二层者apache自己的安全策略。apache
其实,常见 web文件服务器配置任务经常只须要了解几个API的大意思就好了,然而,编程
为了提升专业性,因而下狠心用“新的方法”,系统的捋一遍「httpd服务器配置」做业。安全
一种重复模式是,当咱们须要学习一种新工具,去完成一项新任务,初始认识都很直观的,用本身特定的概念去理解它,只是任务的产出“能行”,咱们基本都不会对这种直观粗浅的认识有任何怀疑。例如,“我就是把一个网站搞起来”,“配置一下apachet先”,而进步正是要对这些粗浅直观的做“更新”。服务器
EM:专家与外行的区别是,对于一个概念,专家会有丰富的内涵。网络
其实,「配置一个http服务器」是指根据某web应用程序的特性,进行httpd服务状态(实例)的定制; 不一样的web应用程序的特性不一样,一台服务器「又」可运行多个web应用程序,故httpd服务状态的定制不是特别的简单。架构
“一个网站搞起来”可改成「定制httpd运行实例」,而这个任务须要多方面的知识,例如http协议(URL 主机 dns),linux服务器管理,web应用架构等。app
http服务器是 web应用程序的一部分,不是所有;至少还有应用程序的源文件数据。另外,http服务器可当作特殊文件服务——使用http(而不像ftp)协议,为网络用户提供文件访问服务。而提供静态文件的http服务器(加文件)可称为网站,而提供动态生成内容的可归为「web应用程序」
http服务器是特殊文件服务器,网络用户只是通常系统用户的一种,因此要管理网站/「web应用程序」的文件的权限。 网站/「web应用程序」可统称「Web文件服务实例」;
在本机登陆的用户可访问(read)系统中大部分数据文件,能够在本身的home随意删改文件;从网络端口进来的http代理用户则必须严格控制其“可视空间”和操做行为。
++
产出1:将个人静态网站共享(出去)
++ 就像工具备多个方面,例如API有不少,工具针对的做业任务也相对应是复合的,任务概述必定是抽象的(复杂的任务不能三句话详细描述)。复合的任务能够具体再分解为多个子任务,就像一个复合产品上有多个组成部分同样。
「定制httpd运行实例」的前提是,一台可用的网络主机,因此定制从端口等,默认像IP地址等基础功能;
配置http 文件服务器 分两大子任务:第一 ,是网络服务器的http服务功能; 第二,文件目录的共享权限;
#目录权限
httpd has the capability to serve many different websites simultaneously. This is called Virtual Hosting.
`Scope of Directives 配置指令是范围属性?服务器能够有多个配置主体实例(主机,虚拟主机,目录等) 这个得先要明白,配置什么。「httpd运行实例」能同时运行多个网站/web应用,不一样的应用有不一样的形式,例如两个网站都会“根目录”形式属性,因此同一个配置项(DocumentRoot)限定一个特定范围(文件服务实例)内; Directives in the configuration files may apply to the entire server, or they may be restricted to apply only to particular directories, files, hosts, or URLs.
#配置文件 Configuration Files
`httpd的配置文件是一个包含配置指令(directives)的文本文件 `配置指令directive httpd做为一种Web服务器软件,主要功能是处理HTTP请求,故配置指令的主要类型是,配置处理HTTP请求的行为。 固然还有很多“元”级任务须要动态配置,例如AccessFileName directive定义.htaccess Files
`配置文件位置、名称及组成 Apache的「主配置文件」一般叫httpd.conf ,其位置是编译时肯定的,但能够用命令行参数 -f 来改变。另外,还能够用Include指令和通配符附加许多其余配置文件。 $ gedit /etc/httpd/conf/httpd.conf
`「主配置文件」与.htaccess
`配置变动及重启生效 Changes to the main configuration files are only recognized by httpd when it is started or restarted.
`TypesConfig指令指定MIME类型信息 The server also reads a file containing mime document types; the filename is set by the TypesConfig directive, and is mime.types by default.
`一行一配置指令directive httpd configuration files contain one directive per line. 反斜扛"" 续行。
`配置参数(数据)用空格与指令分隔 Arguments to directives are separated by whitespace. If an argument contains spaces, you must enclose that argument in quotes.
`注释 Lines that begin with the hash character "#" are considered comments, and are ignored. Comments may not be included on the same line as a configuration directive.
`编程或动态配置 The values of variables defined with the Define of or shell environment variables can be used in configuration file lines using the syntax ${VAR}.
`语法检查 You can check your configuration files for syntax errors without starting the server by using apachectl configtest or the -t command line option.
Directives placed in the main configuration files apply to the entire server. If you wish to change the configuration for only a part of the server, you can scope your directives by placing them in , , , , , and sections. These sections limit the application of the directives which they enclose to particular filesystem locations or URLs. They can also be nested, allowing for very fine grained configuration.
httpd has the capability to serve many different websites simultaneously. This is called Virtual Hosting. Directives can also be scoped by placing them inside sections, so that they will only apply to requests for a particular website.
Although most directives can be placed in any of these sections, some directives do not make sense in some contexts. For example, directives controlling process creation can only be placed in the main server context. To find which directives can be placed in which sections, check the Context of the directive. For further information, we provide details on How Directory, Location and Files sections work.
`去中心化 httpd allows for decentralized management of configuration via special files placed inside the web tree. The special files are usually called .htaccess, but any name can be specified in the AccessFileName directive.
`做用于本目录以及全部子目录 Directives placed in .htaccess files apply to the directory where you place the file, and all sub-directories. The .htaccess files follow the same syntax as the main configuration files. `做用于每个请求,配置无需重启 Since .htaccess files are read on every request, changes made in these files take immediate effect.