Apache configuration in centos

Source: Internet
Author: User

Install httpd in the ghost source package.

(1) Static default installation. The command is as follows:

After the preceding steps, run the following command to check the installed modules:

Check whether the module is activated, for example:

The module is not activated. To add a module, run the following command to load it:

Then we can see that the module has been loaded and activated, as shown below:

(2) dynamically install and load all modules. The command is as follows:

After installation and loading, you can see the following information:

By comparison, we recommend dynamic and complete installation.

Detailed description of parameters in the ⒉ Apache configuration file.

The entire explanation is for the Apache that comes with the system cent OS 5.0 installation.

(1) first, let's take a look at the relative structure of Apache.

/Etc/httpd/CONF/httpd. conf: The main configuration file, which is mainly set to it;

/Etc/httpd/CONF. d/*. conf: Additional parameter configuration. If you do not want to modify the original configuration file httpd. conf, you can separate your settings, for example, create/etc/httpd/CONF. d/child. conf, which is loaded when Apache is started;

/Usr/lib/httpd/modules/: Apache supports many modules, including all the modules you want;

/Var/www/html/: The default 'homepage' directory. The directory where the information displayed is located when you enter http: // localhost;

/Var/www/error/: When the configuration error or browser request information is incorrect, the error message displayed on the browser is based on this directory preset;

/Var/www/icons/: It provides some small icons by default provided by Apache. You can use them at will. The information displayed when you enter http: // localhost/icons;

/Var/www/cgi-bin/: By default, the directory for some executable CGI (web page program) programs is placed;

/Var/log/httpd/: The default Apache login information is stored here. For websites with high traffic, be careful when setting this directory;

/Usr/sbin/apachectl: The main Startup File of Apache is actually shell script;

/Usr/sbin/httpd: Apache binary Startup File.

(2) explanation of the main configuration file httpd. conf.

The Basic Setting format is as follows, for example, setting the directory/var/www/html:

① Httpd. conf configuration is divided into three parts ):

ServerTokens OSInform the user of the version and operating system of the WWW Server

Serverroot "/etc/httpd"Apache installation path

Pidfile run/httpd. PIDPut the PID directory to facilitate software management. It is a relative path.

Timeout 120Persistent connection if you wait for more than 120 seconds, the connection is disconnected.

Keepalive offWhether persistent connections are allowed. The default value is no.

Maxkeepaliverequests 100Change the number of people who keep the connection to 0, that is, there is no limit on the number of people.

Keepalivetimeout 15The connection timeout allowed for keepalive

The above are two sets related to the server connection resources, which are divided into worker and prefork. The two sets are similar, and only one set is used at httpd startup, /usr/sbin/httpd executes the prefork group,/usr/sbin/httpd. the worker executes the worker group and defaults to the prefork group. You can query and use the group in/etc/sysconfig/httpd.

Listen 80Listening port number

Loadmodule access_module modules/mod_access.so

...... (Omitted below)Display loaded module groups

Include Conf. d/*. confMake the configuration file *. conf under the/etc/httpd/CONF. d/directory read

User Apache

Group ApacheWho started the Apache server

(2) configure the "master" Service ('main' server configuration ):

Serveradmin root @ localhostEmail Notification to whom webpage errors occur

UseCanonicalName offWhether to use the standard host name. The default value is no.

DocumentRoot "/var/www/html"The path where the webpage is stored and the root directory of the document

<Directory> is used to set directory permissions. The previous set is for the httpd preset environment and is set to "/". The latter set to the root directory/var/www/html. Several settings are described as follows:

Options indicates actions that can be performed in the directory. The options include none, all, indexes, followsymlinks, execcgi, Des, and Multiviews. None indicates browsing only; All indicates doing anything, but does not include Multiviews; indexes indicates displaying the file name in the entire directory when there is no homepage file; followsymlinks allows the linked files in this directory to be linked out of this directory; execcgi allows the sub-directory to have the permission to execute CGI programs; des allows some server-side
The include program can be executed. Multiviews is related to language priority.

AllowOverride indicates whether to enable the Additional configuration file. htaccess permission. it overwrites the httpd. conf settings, including all, authconfig, indexes, limits, and none. All indicates full enable; authconfig is only enabled when web page authentication is enabled; indexes allows index activation; limits allows users to manage browsed permissions using allow, deny, and order; none indicates files. htaccess is invalid.

Order determines whether the permission can be browsed. The options are deny, allow, allow, deny, deny, and allow. If there is no write Rule, the default options are allow and allow, deny is the opposite. Allow from all is open to all users.

This is the setting for configuring the Home Directory of a personal user. It is disabled by default.

Restrict all files starting with. ht to prevent web users from viewing them.

Typeconfig CONF/mime. TypesDefine where to query the mime. types File

Defaulttype text/plainDefines the default MIME type provided by the server when the MIME type cannot be determined. When the service mainly contains text or HTML documents, "text/plain" is a good choice. If most of them are binary documents, such as software or images, the "application/octer-stream" should be used"

Module mod_mime_magic allows the server to use different clues (hints) from a file of its own type. This mimemagicfile command defines the file where hints defines

Hostnamelookups offSpecifies whether to record the client name or IP address. The default value is off and the IP address is recorded.

Errorlog logs/error_logLocation of the log file that is logged incorrectly

Loglevel warnControl the number of logs recorded in the error log file. Possible values include debug, info, notice, warn, error, crit, alert, and emerg.

Define log format

Customlog logs/access_log commonSpecifies the location and format of the access log file. If this command is not defined in <virtualhost>, the transmission information will be recorded here. If this command is defined, it will be recorded in the location you specified.

Serversignature onAdd a line of information containing the server version and virtual host name to the server-generated output page at will

Alias/icons/"/var/www/icons /"Use alias

Set directory/var/www/icons Permissions

ScriptAlias/cgi-bin/"/var/www/cgi-bin /"Essentially, like aliases, except that the documentation here is processed as a program during request processing

Indexoptions fancyindexing versionsort namewidth = * htmltableControl Server-generated directory list display features

The addicon * Command tells the server how to display image files with Different Extensions. It is only applicable to the fancyindexed command.

Defaulticon/icons/unknown.gifProvides processing for files without explicitly defining icons

Readmename readme.htmlSpecify the name of the README file that the server finds by default and add it to the directory list.

Headername header.htmlName of the file with the specified directory list prefix

Indexignore .?? **~ * # Header * readme * rcs cvs *, V *, TSpecifies the file name set ignored by the Directory Index and not included in the list. Wildcards of the shell type are supported.

Language of the specified document

Languagepriority en ca CS da de El EO es et Fr he hr it Ja ko ltz nn no PL Pt-Br Ru sv zh-cn zh-TWSort languages in descending order

Forcelanguagepriority prefer fallbackProvides a result page when communication or no acceptable language match is available

Adddefacharcharset UTF-8Specify the default character set for all pages sent

Addtype allows you to add or override mime for the specified file type. the mime configured in the types file, addhandler allows you to map a specified file extension to "handlers", and the behavior is irrelevant to the file type, this can be compiled to the server or added to the Action Command.

Addhandler type-map VaRThis is the default setting to allow Apache's "It worked" page to be distributed in multiple languages

This allows you to analyze the .shtml document containing (ssi)on the server end

This is an international error response setting.

Change standard HTTP Response Behavior to handle known browser Problems

③ Virtual hosts ):

This is a virtual machine setting instance configuration, not enabled.

3. Apache applications.

(1) Apache startup.

There are two ways to start httpd:

After it is started, enter the local address in the browser to display

This is an Apache welcome interface, because the root directory/var/www/html is empty. After I create an HTML file in the root directory, for example:

The webpage content changes as follows:

(2) configure the personal user homepage.

 

Modify the configuration file to find the configuration.

 

Remember to restart,

Next, create a personal user directory, add Test content, and pay attention to permission modification (important ),

Connection test, cannot open,

In the past, SELinux did not enable httpd support. The following changes were made:

The test is successful,

Because the options on the home page contains the followsymlinks parameter, you can also directly use the link file to connect to other directories ,:

Test

(3) Start the CGI program execution permission in a directory.

The default directory/var/www/cgi-bin of Apache is used to place the CGI program to be executed. The directory permission configuration is as follows:

Change it to:, and then find# Addhandler
CGI-script. cgi
Modify the line to addhandler CGI-script. cgi. pl. After the configuration is complete, restart httpd.

Create and test the CGI program test. cgi and modify the permission,

Input the address to http: // 218.108.235.78/cgi-bin/test. cgi Test

(4). htaccess and webpage Authentication Settings.

Apache provides the authentication function to easily set the web page to be protected.

1. First, create the directories and materials to be protected,

② Modify the configuration file to ensure the following configuration exists:

This restricts all files starting with. HT, prevents web users from viewing them, and then adds the following Configuration:

③ Create a. htaccess file in the protected directory,

The red line parameters are interpreted as follows: authname displays the prompt text; authtype is the authentication type, select the default 'basic '; authuserfile determines the account and password file to be used; require connects to available accounts.

④ Create the password file Apache. passwd,

Note that the file name must be consistent with the authuserfile in the. htaccess file.

⑤ Test, successful

Configure Virtual Hosts

The virtual host here refers to the fact that multiple 'master webpages 'exist on a host, and these URLs actually point to the same IP address.

1. create the required directory first,

② Configure the virtual host and directly create a separate configuration file Virtual. conf under the/etc/httpd/CONF. d directory,

Note: After a VM is used, the original host name should also be written. The red lines on the figure indicate the original host. Remember to restart Apache.

③ Test and modify the c: \ windows \ system32 \ drivers \ etc \ hosts file. Add the following content :,

Resolve the domain name to an IP address. The configuration is successful as follows:

Related Article

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.