《apache入門指南》要點:
本文介紹了apache入門指南,希望對您有用。如果有疑問,可以聯系我們。
相關主題:apache配置
英文原文網址:http://httpd.apache.org/docs/2.4/getting-started.html
翻譯辦法:google translate翻譯后,本人重新校對.感觸是,不得不說google翻譯準得驚人,準確率超過95%,我的改動不超過一百字.但是確實沒有達到完全代替人工的程度.
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的新手,或者從未運行過一個網站,您可能不知道從哪里開始,或者不知道要問什么問題.本文將引導您了解根基知識.
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.
客戶端,服務器和URL
Web上的地址是以URL(統一資源定位符)的形式給出的.URL指定了協議(例如http),服務器名稱(例如www.apache.org),URL路徑(例如/docs/current/getting-started.html),也可能是一個查詢字符串(例如?arg=value),用于將額外的參數傳遞給服務器.
客戶端(例如,Web瀏覽器)使用指定的協議連接到服務器(例如,您的Apache HTTP Server),并使用URL路徑哀求資源.
URL路徑可以表現服務器上的任何數量的東西.它可能是一個文件(如getting-started.html)一個處理程序(如服務器狀態)或某種程序文件(如index.php).我們將在“ 網站內容”部分中詳細討論.
服務器將發送由狀態碼和可選的響應主體組成的響應.狀態代碼指示哀求是否成功,如果沒有成功,則會指示出現了什么樣的錯誤狀況.這告訴客戶端接下來該做什么.您可以閱讀HTTP Server wiki中可能的響應代碼.
事務的詳細信息和任何錯誤條件都將寫入日志文件.這將在日志文件和故障排除部門中詳細討論.
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.
主機名和DNS
為了連接到服務器,客戶端首先必須將servername解析為IP地址 - 服務器在Internet上的位置.因此,為了使您的Web服務器可拜訪,服務器名稱必須位于DNS中.
如果您不知道如何執行此操作,則必要聯系您的網絡管理員或Internet服務提供商,為您執行此步驟.
多個主機名可能指向相同的IP地址,而且可以將多個IP地址附加到同一物理服務器.因此,您可以使用稱為虛擬主機的功能在同一物理服務器上運行多個網站.
如果您正在測試Internet訪問不了的服務器,則可以在主機文件中放置主機名,以便進行本地解析.例如,您可能希望在主機文件中添加一個記錄,將對www.example.com的哀求映射到本地系統,以進行測試.這個記錄可能寫成這樣:
127.0.0.1 www.example.com
主機文件可能位于/etc/hosts或C:\Windows\system32\drivers\etc\hosts.
您可以在Wikipedia.org/wiki/Hosts_(file)上了解有關hosts文件的更多信息,以及有關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通過簡單的文本文件進行配置.這些文件可能處于分歧的位置,具體取決于您如何安裝服務器.這些文件的常見位置可以在httpd維基中找到.如果從源安裝了httpd,則配置文件的默認位置為/usr/local/apache2/conf.默認配置文件通常稱為httpd.conf.當然,這也可能因服務器的發行版分歧而存在區別.(譯者注:apache2 通過apt-get 安裝 配置文件在/etc/apache2里.另外總體配置在apache2.conf中.)
配置經常被分成多個較小的文件,便于管理.這些文件通過Include指令加載.這些子文件的名稱或位置不是固定的,并且可能由于安裝的不同有很大差異.支配和細分這些文件對你來說是最有意義的.如果你認為默認的文件支配有什么不妥,請隨意重新排列組合.
我們通過在這些配置文件中放置配置指令來配置服務器.指令是一個癥結字,后跟一個或多個設置其值的參數.
一般來說,“ 我應該在哪里提出這個指令? ”這個問題的答案是:這要取決于你想要這個指令有怎樣的作用域.如果是全局設置,它應該出現在總體配置文件中,而不該在<Directory>, <Location>, <VirtualHost>或其他部分.而如果只應用于特定的目錄,那么它應該進入一個引用該目錄的<Directory>部分,依此類推.有關這些部分的進一步討論,請參閱配置部分文檔.
除了主配置文件之外,某些指令也可能位于內容目錄中的.htaccess文件中..htaccess文件主要適用于無法拜訪主服務器配置文件的用戶.您可以在.htaccess howto中閱讀更多關于.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.
網站內容
網站內容可以采取許多分歧的形式,但可以大致分為靜態和動態內容.
靜態內容是HTML文件,圖像文件,CSS文件以及文件系統中的其他文件. DocumentRoot指令指定文件系統中應該放置這些文件的地位.該指令是全局設置的,也可以是每個虛擬主機.查看您的配置文件以確定如何為您的服務器設置.
通常,當哀求沒有指定文件名的目錄時,服務器將默認回應一個名為index.html的文檔.例如,如果DocumentRoot設置為/var/www/html,并且哀求是針對http://www.example.com/work/,則文件/var/www/html/work/index.html將被提供給客戶端.
動態內容是在哀求時生成的任何內容,不同的哀求又不同的回應.有多種方式可以生成動態內容.各種處理程序可用于生成內容.你可能會編寫CGI程序來為您的網站生成內容.
也可以使用第三方模塊,如mod_php來編寫執行各種操作的代碼.許多使用各種語言和工具編寫的第三方應用程序可以在您的Apache HTTP服務器上進行下載和安裝.介紹這些第三方模塊已經超越了本文檔應該涵蓋的范圍,您可以找到相關文檔或到其他支持論壇來解答您的疑問.
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管理員,您最名貴的資產是日志文件,特別是錯誤日志.排除任何沒有錯誤日志的問題,就像開車閉眼.
錯誤日志的位置由可以全局設置或每個虛擬主機設置的ErrorLog指令定義.錯誤日志中的條目告訴您出了什么問題,何時出現.他們經常也會告訴你如何解決它.每個錯誤日志消息包含一個錯誤代碼,您可以在線搜索更詳細的描述如何解決問題.您還可以將錯誤日志配置為包含一個日志ID,然后可以將其與訪問日志條目相關聯,以便您可以確定導致錯誤條件的哀求.
您可以瀏覽有關登錄日志文檔的更多信息.
維易PHP培訓學院每天發布《apache入門指南》等實戰技能,PHP、MYSQL、LINUX、APP、JS,CSS全面培養人才。