网络学习之Apache http server get start

来源:互联网 发布:网页制作什么软件好 编辑:程序博客网 时间:2024/06/10 05:51

http://httpd.apache.org/docs/trunk/getting-started.html

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.

  • Clients, Servers, and URLs
  • Hostnames and DNS
  • Configuration Files and Directives
  • Web Site Content
  • Log Files and Troubleshooting
  • What Else Do I Need To Know?
  • Comments
top

Clients, Servers, and URLs

Client--->URLs---->Server

Server--->Response--->Client

URLs:

a) a protocol (e.g. http), 

b) a servername (e.g. www.apache.org), 

c) a URL-path (e.g./docs/current/getting-started.html), 

1) a file (like getting-started.html)

2) a handler (like server-status) 

3) some kind of program file (like index.php). We'll discuss this more below in the Web Site Content section.

d) possibly a query string (e.g. ?arg=value) used to pass additional arguments to the server.

 response:

a) a status code

b) optionally, a response body. 


top

Hostnames and DNS

Client--->DNS--->Server

DNS:  serverName--->IP address

What's virtual hosts?

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.

How to local testing?

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.

top

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 calledhttpd.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.

top

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/html and 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 handlersare 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.

top

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 a 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.

top

What Else Do I Need To Know?

This document covers only the bare basics. We hope that this gets you started, but there are many other things that you might need to know. Here's a partial list of what you might be looking for:

  • Authentication and Authorization (password protecting resources)
  • Access Control
  • Setting up SSL
  • Frequently Asked Questions



0 0
原创粉丝点击