Linux Apache Web Server (Continued 1)

Source: Internet
Author: User

Before proceeding, we must tell you that Apache has adopted a series of default values during installation and has enabled the WWW server to run. You only need to connect the host installed with Linux + Apache to the Internet, and then store the home page under the "/home/httpd" directory.

The following describes the meanings of some of the most important configuration options, so that you can prepare the server with the minimum effort and minimum configuration.

4.1 httpd. conf

Httpd. conf is the main configuration file. It tells the server how to run it.

1. servertype standalone | inetd

This configuration option specifies how to run the web server. Apache can be run in two ways

Row server: Standalone (independent) and inetd (run by inetd ).

The standalone parameter indicates that a Web service process listens for client requests in the background in a separate waiting process. If yes, a sub-process is generated to serve it.

The inetd parameter indicates that the Web service is not supported in the form of a separate waiting process. Instead, the super server inetd waits for the process to do the work. When it receives a web service request from a client, it starts a web service process to serve it.

From a functional perspective, the two methods are almost the same. But there is a big difference between them, the difference lies in the server performance. A server process running by inted exits immediately after it finishes requesting services. In standalone mode, the sub-WWW server processes need to be suspended for a period of time before exiting, which provides them with the opportunity to serve new requests again.

In standalone mode, there is no overhead for starting a new process for each request, so it is more efficient. inetd mode is considered to be more secure than standalone mode.

Standalone mode:

In this mode, the WWW server listens for connection requests from specific ports. When the client sends

When configuring a connection request for a port address, the master server process starts the WWW Service process to serve the request. As shown in:

Figure 2 independent server

In addition, you also need to tell the master server the specific port address for listening by the process, using the command:

Port [number] (default value: 80)

Inetd Mode

Inetd is an Internet daemon (a server process) that listens to connection requests from ports smaller than 1024 ). Different from the preceding method, when the client system sends a connection request to the WWW server, inetd starts a WWW server process, and the process then serves the request and exits after the service is completed. As shown in:

Figure 3 servers started by inetd

If you choose to run Apache through the inetd server, you need to edit the/etc/inetd. conf file to add a new record for Apache:

Httpd stream tcp Nowait httpd/etc/httpd/bin/httpd-F/etc/httpd/CONF/httpd. conf

After modifying the/etc/inetd. conf file, you need to add a line in/etc/services.

Httpd 80/tcp httpd

After the preceding modification, You need to restart the inetd process. First, use the following command to obtain the inetd process ID:

PS auxw | grep inetd

Then run the command: kill-HUP

In RedHat Linux, the inetd server is used by default to run Apache, so as long as you select httpd during installation, the above work has been completed on your behalf during installation.

Ii. Other configuration options

The server admin command is used to set the e-mail address of the web administrator. This address may occur when a system connection error occurs, so that visitors can promptly inform the web administrator of the situation.

Command Format: Server Admin [you e-mail address]

Example: Server Admin admin@xxx.com

The errorlog command is used to specify the name and path of the error record file.

Command Format: errorlog [log filename]

Example: errorlog/var/httpd/error. Log

Timeout command, as long as the client has not completed a request within the specified number of seconds, the server will terminate the request service. If the network speed is slow, we recommend that you set a large value here. To give the client more opportunities.

Command Format: timeout [second]

Example: timeout 120

Serverroot command, which specifies where to save server configurations, errors, and log files.

Command Format: serverroot [fully qualified path name]

Example: serverroot/etc/httpd

Servername command, which configures the server's Internet host name

Command Format: servername [host name]

Example: servername www.xxx.com

4.2 SRM. conf

SRM. conf is a resource configuration file that tells the server what resources you want to provide on the WWW site, where and how to provide them.

The DocumentRoot command is used to specify the address of the main document.

Command Format: DocumentRoot [path]

Example: DocumentRoot/home/httpd/html

The userdir command is used to specify the location of the personal homepage. If you have a user named test, the main directory is "/home/test". When the client enters "http: // yourdomain /~ Test, the system will go to the corresponding directory "/home/test/userdir/" to find. "Userdir" is the specified directory set in the userdir command.

Command Format: userdir [path]

Example: userdir public_html

The directoryindex command is used to declare the name of the home page file. In general, we use javasindex.html#or javasindex.htm as the homepage file name. ".

Command Format: direcotryindex [filename]

Example: direcotryindex index.html index.htm

ScriptAlias command, which is a scriptProgramDirectory alias. See section 4.7.

Command Format: ScriptAlias [/alias/] [fullly qualified path for script directory]

Example: ScriptAlias/cgi-bin // home/httpd/cgi-bin

4.3 Access. conf configuration

The access. conf file is used to set access permissions for files, directories, and script projects on the WWW site. The uncommented part of the First Section of the file is as follows:

Option indexes includes execcgi followsymlink

AllowOverride none

Order allow, deny

Allow from all

It should be noted that this part ends at the beginning. This indicates that the portion in the middle is for the specified directory "/home/httpd/html.

1. The option command has many parameters. The meaning of each parameter is as follows:

All allow all of the following functions (except Multiviews );

Multiviews: Multiviews that allow content negotiation;

Indexes: If no index file exists in this directory, display is allowed.

Select files under this directory;

IncludesNOEXEC allows SSI (server-side supported des), but not

Use the # exec and # include functions;

Supported des allows SSI;

Followsymlinks allows symbols to be linked to other directories;

Execcgi allows CGI to be used in this directory.

2. the AllowOverride command is used to determine whether the permission set in the "access. conf" file can be overwritten by the permission set in the file ". htaccess. It has two parameters:

All is allowed;

None is not allowed to be overwritten.

3. Order command: Used to set who can get control from this server. It also has two parameters:

Allow can achieve control;

Deny prohibits access control.

Now let's take a look at the definition of the "/home/httpd/html" directory settings: Allow to use this directory. If the index.htm file does not exist, list the directory information for selection, allow SSI, and allow CGI program execution, dynamic connection is enabled. It is no longer allowed to overwrite the permissions set here in the file ". htaccess. This allows everyone to gain control.

The second part of the file is not annotated as follows:

Option execcgi

AllowOverride none

This indicates that the "/home/httpd/cgi" directory is set to run CGI programs in the current directory. The permission set in the file ". htaccess" is not allowed to overwrite the permission set here.

It should be noted that in different Linux systems, the information displayed in this file is not exactly the same, but according to the information given here, you can refer to the Command explanation to understand the settings in the file and modify the settings as needed.

4.4 make the new configuration take effect

In the above section, we may have changed the corresponding configuration options based on new requirements. If we want

Make the new configuration take effect immediately. We must restart the Web service process. In Linux, we can easily restart the Web service process by using the command line.

/etc/rc. d/init. d/httpd restart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.