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.