《apache入門指南》要點(diǎn):
本文介紹了apache入門指南,希望對您有用。如果有疑問,可以聯(lián)系我們。
相關(guān)主題:apache配置
英文原文網(wǎng)址:http://httpd.apache.org/docs/2.4/getting-started.html
翻譯辦法:google translate翻譯后,本人重新校對.感觸是,不得不說google翻譯準(zhǔn)得驚人,準(zhǔn)確率超過95%,我的改動不超過一百字.但是確實(shí)沒有達(dá)到完全代替人工的程度.
If you're completely new to the Apache HTTP Server, or even to running a website at all, you might not know where to start, or what questions to ask. This document walks you through the basics.
如果您完全是Apache HTTP Server的新手,或者從未運(yùn)行過一個(gè)網(wǎng)站,您可能不知道從哪里開始,或者不知道要問什么問題.本文將引導(dǎo)您了解根基知識.
Clients, Servers, and URLs
Addresses on the Web are expressed with URLs - Uniform Resource Locators - which specify a protocol (e.g. http), a servername (e.g. www.apache.org), a URL-path (e.g./docs/current/getting-started.html), and possibly a query string (e.g. ?arg=value) used to pass additional arguments to the server.
A client (e.g., a web browser) connects to a server (e.g., your Apache HTTP Server), with the specified protocol, and makes a request for a resource using the URL-path.
The URL-path may represent any number of things on the server. It may be a file (like getting-started.html) a handler (like server-status) or some kind of program file (like index.php). We'll discuss this more below in the Web Site Content section.
The server will send a response consisting of a status code and, optionally, a response body. The status code indicates whether the request was successful, and, if not, what kind of error condition there was. This tells the client what it should do with the response. You can read about the possible response codes in HTTP Server wiki.
Details of the transaction, and any error conditions, are written to log files. This is discussed in greater detail below in the Logs Files and Troubleshooting section.
客戶端,服務(wù)器和URL
Web上的地址是以URL(統(tǒng)一資源定位符)的形式給出的.URL指定了協(xié)議(例如http),服務(wù)器名稱(例如www.apache.org),URL路徑(例如/docs/current/getting-started.html),也可能是一個(gè)查詢字符串(例如?arg=value),用于將額外的參數(shù)傳遞給服務(wù)器.
客戶端(例如,Web瀏覽器)使用指定的協(xié)議連接到服務(wù)器(例如,您的Apache HTTP Server),并使用URL路徑哀求資源.
URL路徑可以表現(xiàn)服務(wù)器上的任何數(shù)量的東西.它可能是一個(gè)文件(如getting-started.html)一個(gè)處理程序(如服務(wù)器狀態(tài))或某種程序文件(如index.php).我們將在“ 網(wǎng)站內(nèi)容”部分中詳細(xì)討論.
服務(wù)器將發(fā)送由狀態(tài)碼和可選的響應(yīng)主體組成的響應(yīng).狀態(tài)代碼指示哀求是否成功,如果沒有成功,則會指示出現(xiàn)了什么樣的錯(cuò)誤狀況.這告訴客戶端接下來該做什么.您可以閱讀HTTP Server wiki中可能的響應(yīng)代碼.
事務(wù)的詳細(xì)信息和任何錯(cuò)誤條件都將寫入日志文件.這將在日志文件和故障排除部門中詳細(xì)討論.
Hostnames and DNS
In order to connect to a server, the client will first have to resolve the servername to an IP address - the location on the Internet where the server resides. Thus, in order for your web server to be reachable, it is necessary that the servername be in DNS.
If you don't know how to do this, you'll need to contact your network administrator, or Internet service provider, to perform this step for you.
More than one hostname may point to the same IP address, and more than one IP address can be attached to the same physical server. Thus, you can run more than one web site on the same physical server, using a feature called virtual hosts.
If you are testing a server that is not Internet-accessible, you can put host names in your hosts file in order to do local resolution. For example, you might want to put a record in your hosts file to map a request for www.example.com to your local system, for testing purposes. This entry would look like:
127.0.0.1 www.example.com
A hosts file will probably be located at /etc/hosts or C:\Windows\system32\drivers\etc\hosts.
You can read more about the hosts file at Wikipedia.org/wiki/Hosts_(file), and more about DNS at Wikipedia.org/wiki/Domain_Name_System.
主機(jī)名和DNS
為了連接到服務(wù)器,客戶端首先必須將servername解析為IP地址 - 服務(wù)器在Internet上的位置.因此,為了使您的Web服務(wù)器可拜訪,服務(wù)器名稱必須位于DNS中.
如果您不知道如何執(zhí)行此操作,則必要聯(lián)系您的網(wǎng)絡(luò)管理員或Internet服務(wù)提供商,為您執(zhí)行此步驟.
多個(gè)主機(jī)名可能指向相同的IP地址,而且可以將多個(gè)IP地址附加到同一物理服務(wù)器.因此,您可以使用稱為虛擬主機(jī)的功能在同一物理服務(wù)器上運(yùn)行多個(gè)網(wǎng)站.
如果您正在測試Internet訪問不了的服務(wù)器,則可以在主機(jī)文件中放置主機(jī)名,以便進(jìn)行本地解析.例如,您可能希望在主機(jī)文件中添加一個(gè)記錄,將對www.example.com的哀求映射到本地系統(tǒng),以進(jìn)行測試.這個(gè)記錄可能寫成這樣:
127.0.0.1 www.example.com
主機(jī)文件可能位于/etc/hosts或C:\Windows\system32\drivers\etc\hosts.
您可以在Wikipedia.org/wiki/Hosts_(file)上了解有關(guān)hosts文件的更多信息,以及有關(guān)Wikipedia.org/wiki/Domain_Name_System的 DNS的更多信息.
Configuration Files and Directives
The Apache HTTP Server is configured via simple text files. These files may be located any of a variety of places, depending on how exactly you installed the server. Common locations for these files may be found in the httpd wiki. If you installed httpd from source, the default location of the configuration files is /usr/local/apache2/conf. The default configuration file is usually called httpd.conf. This, too, can vary in third-party distributions of the server.
The configuration is frequently broken into multiple smaller files, for ease of management. These files are loaded via the Include directive. The names or locations of these sub-files are not magical, and may vary greatly from one installation to another. Arrange and subdivide these files as makes the most sense to you. If the file arrangement you have by default doesn't make sense to you, feel free to rearrange it.
The server is configured by placing configuration directives in these configuration files. A directive is a keyword followed by one or more arguments that set its value.
The question of "Where should I put that directive?" is generally answered by considering where you want a directive to be effective. If it is a global setting, it should appear in the configuration file, outside of any <Directory>, <Location>, <VirtualHost>, or other section. If it is to apply only to a particular directory, then it should go inside a <Directory>section referring to that directory, and so on. See the Configuration Sections document for further discussion of these sections.
In addition to the main configuration files, certain directives may go in .htaccess files located in the content directories. .htaccess files are primarily for people who do not have access to the main server configuration file(s). You can read more about .htaccess files in the .htaccess howto.
配置文件和指令
Apache HTTP Server通過簡單的文本文件進(jìn)行配置.這些文件可能處于分歧的位置,具體取決于您如何安裝服務(wù)器.這些文件的常見位置可以在httpd維基中找到.如果從源安裝了httpd,則配置文件的默認(rèn)位置為/usr/local/apache2/conf.默認(rèn)配置文件通常稱為httpd.conf.當(dāng)然,這也可能因服務(wù)器的發(fā)行版分歧而存在區(qū)別.(譯者注:apache2 通過apt-get 安裝 配置文件在/etc/apache2里.另外總體配置在apache2.conf中.)
配置經(jīng)常被分成多個(gè)較小的文件,便于管理.這些文件通過Include指令加載.這些子文件的名稱或位置不是固定的,并且可能由于安裝的不同有很大差異.支配和細(xì)分這些文件對你來說是最有意義的.如果你認(rèn)為默認(rèn)的文件支配有什么不妥,請隨意重新排列組合.
我們通過在這些配置文件中放置配置指令來配置服務(wù)器.指令是一個(gè)癥結(jié)字,后跟一個(gè)或多個(gè)設(shè)置其值的參數(shù).
一般來說,“ 我應(yīng)該在哪里提出這個(gè)指令? ”這個(gè)問題的答案是:這要取決于你想要這個(gè)指令有怎樣的作用域.如果是全局設(shè)置,它應(yīng)該出現(xiàn)在總體配置文件中,而不該在<Directory>, <Location>, <VirtualHost>或其他部分.而如果只應(yīng)用于特定的目錄,那么它應(yīng)該進(jìn)入一個(gè)引用該目錄的<Directory>部分,依此類推.有關(guān)這些部分的進(jìn)一步討論,請參閱配置部分文檔.
除了主配置文件之外,某些指令也可能位于內(nèi)容目錄中的.htaccess文件中..htaccess文件主要適用于無法拜訪主服務(wù)器配置文件的用戶.您可以在.htaccess howto中閱讀更多關(guān)于.htaccess文件的信息.
Web Site Content
Web site content can take many different forms, but may be broadly divided into static and dynamic content.
Static content is things like HTML files, image files, CSS files, and other files that reside in the filesystem. The DocumentRoot directive specifies where in your filesystem you should place these files. This directive is either set globally, or per virtual host. Look in your configuration file(s) to determine how this is set for your server.
Typically, a document called index.html will be served when a directory is requested without a file name being specified. For example, if DocumentRoot is set to /var/www/htmland a request is made for http://www.example.com/work/, the file /var/www/html/work/index.html will be served to the client.
Dynamic content is anything that is generated at request time, and may change from one request to another. There are numerous ways that dynamic content may be generated. Various handlers are available to generate content. CGI programs may be written to generate content for your site.
Third-party modules like mod_php may be used to write code that does a variety of things. Many third-party applications, written using a variety of languages and tools, are available for download and installation on your Apache HTTP Server. Support of these third-party things is beyond the scope of this documentation, and you should find their documentation or other support forums to answer your questions about them.
網(wǎng)站內(nèi)容
網(wǎng)站內(nèi)容可以采取許多分歧的形式,但可以大致分為靜態(tài)和動態(tài)內(nèi)容.
靜態(tài)內(nèi)容是HTML文件,圖像文件,CSS文件以及文件系統(tǒng)中的其他文件. DocumentRoot指令指定文件系統(tǒng)中應(yīng)該放置這些文件的地位.該指令是全局設(shè)置的,也可以是每個(gè)虛擬主機(jī).查看您的配置文件以確定如何為您的服務(wù)器設(shè)置.
通常,當(dāng)哀求沒有指定文件名的目錄時(shí),服務(wù)器將默認(rèn)回應(yīng)一個(gè)名為index.html的文檔.例如,如果DocumentRoot設(shè)置為/var/www/html,并且哀求是針對http://www.example.com/work/,則文件/var/www/html/work/index.html將被提供給客戶端.
動態(tài)內(nèi)容是在哀求時(shí)生成的任何內(nèi)容,不同的哀求又不同的回應(yīng).有多種方式可以生成動態(tài)內(nèi)容.各種處理程序可用于生成內(nèi)容.你可能會編寫CGI程序來為您的網(wǎng)站生成內(nèi)容.
也可以使用第三方模塊,如mod_php來編寫執(zhí)行各種操作的代碼.許多使用各種語言和工具編寫的第三方應(yīng)用程序可以在您的Apache HTTP服務(wù)器上進(jìn)行下載和安裝.介紹這些第三方模塊已經(jīng)超越了本文檔應(yīng)該涵蓋的范圍,您可以找到相關(guān)文檔或到其他支持論壇來解答您的疑問.
Log Files and Troubleshooting
As an Apache HTTP Server administrator, your most valuable assets are the log files, and, in particular, the error log. Troubleshooting any problem without the error log is like driving with your eyes closed.
The location of the error log is defined by the ErrorLog directive, which may be set globally, or per virtual host. Entries in the error log tell you what went wrong, and when. They often also tell you how to fix it. Each error log message contains an error code, which you can search for online for even more detailed descriptions of how to address the problem. You can also configure your error log to contain a log ID which you can then correlate to an access log entry, so that you can determine what request caused the error condition.
You can read more about logging in the logs documentation.
日志文件和故障排除
作為Apache HTTP Server管理員,您最名貴的資產(chǎn)是日志文件,特別是錯(cuò)誤日志.排除任何沒有錯(cuò)誤日志的問題,就像開車閉眼.
錯(cuò)誤日志的位置由可以全局設(shè)置或每個(gè)虛擬主機(jī)設(shè)置的ErrorLog指令定義.錯(cuò)誤日志中的條目告訴您出了什么問題,何時(shí)出現(xiàn).他們經(jīng)常也會告訴你如何解決它.每個(gè)錯(cuò)誤日志消息包含一個(gè)錯(cuò)誤代碼,您可以在線搜索更詳細(xì)的描述如何解決問題.您還可以將錯(cuò)誤日志配置為包含一個(gè)日志ID,然后可以將其與訪問日志條目相關(guān)聯(lián),以便您可以確定導(dǎo)致錯(cuò)誤條件的哀求.
您可以瀏覽有關(guān)登錄日志文檔的更多信息.
維易PHP培訓(xùn)學(xué)院每天發(fā)布《apache入門指南》等實(shí)戰(zhàn)技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養(yǎng)人才。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/11653.html