Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of installing and setting up apache of CentOS web Server

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "the method of installing and setting up CentOS web server apache". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "method of installation and setup of CentOS web server apache" can help you solve the problem.

Install apache using yum

Yum install httpd-y

Files in the apache web server directory

Catalogue

Description

Web site directory

/ var/www

Directory of apache web site files

/ var/www/html

Store web files for web sites

/ var/www/cgi-bin

Store cgi program files

/ var/www/html/manual

Storage server manual

Configuration file

.htaccess

Directory-based configuration file. The. Htaccess file contains access control instructions for files in its directory.

/ etc/httpd/conf

Store configuration files

/ etc/httpd/conf/httpd.conf

Apache web server master profile

Startup script

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

The startup script that holds the web server daemon

/ etc/rc.d/rc3.d/s85httpd

Store startup scripts that connect the / etc/rc3.d directory to the / etc/rc.d/init.d directory

Application file

/ usr/sbin

Store apache web server program files and user programs

/ usr/doc

Store apache web server files

/ usr/log/http

Store apache log files

After installation, you can use the following command to view some installation information about apache

To check the syntax of the apache configuration file, you can use the following command

To view the apache compilation configuration parameters, you can use the following command

Apachectl-v

You can also view the editing module of apache using the following command

Restart the apache service

Basic configuration of apache server

The configuration of the apache server is mainly realized by compiling the main configuration file httpd.conf of apache. It is important to note that after modifying the httpd.conf file, the httpd service must be restarted for the changes to take effect.

The location of the httpd.conf file varies with the installation method, and it is usually stored in the / etc/httpd/conf directory if you install it using rpm, or in the confconfsubdirectory of the apache installation directory if you install it using compiled source code. Because httpd.conf is a text file, you can edit it using any text editor, such as vi.

The httpd.conf configuration file mainly consists of three parts, namely, the global environment setting (section 1:global environment), the master server configuration (section 2 virtual host server configuration) and the virtual host setting.

(section 3: vitual hosts)

Each part has a corresponding configuration statement, and the syntax of all configuration statements is

Configuration parameter name (option) parameter valu

Although configuration statements can be placed anywhere in the file, all option instructions are case-insensitive in order for http.conf 's configuration statements to be case-insensitive except for the selected parameter values. You can use # to indicate comments before each line of statements.

Set the root path

The root directory of apache server refers to the directory where apache stores configuration files and log files. The configuration parameter is serverroot.

By default, the root directory is at "/ etc/httpd". The root directory generally contains conf and logs subdirectories. The command is as follows:

Serverroot "/ etc/httpd"

Set listening ip address and port number

By default, apache listens to client requests on the tcp80 port of the ip address. The command is as follows:

Listen 80

You can use the listen statement to listen for client requests on multiple addresses and ports. If the setting server refers to listening for requests from port 80 of 12.34.56.78 and port 8080 of 192.168.1.144, you can use the following configuration statement:

Listen 12.34.56.78:80

Listen 192.168.1.144:8080

Set up the system administrator e-mail

When an error occurs when the client accesses the server, the server usually returns an error prompt web page to the client, which usually contains the e-mail address of the system administrator in order to eliminate the error. You can use the configuration parameter serveradmin to set the administrator's e-mail, for example:

Serveradmin admin@your-domain.com

Set the server host name

To make it easier for apache to identify the server's own information, you can use the configuration parameter servername to set the host name of the server. If the server has a domain name, enter the server domain name: if there is no domain name, enter the server's ip address. The command is as follows:

Servername www.example.com:80

# servername 192.168.0.47:80

Set the home directory path

The configuration parameter for the default path of the apache server home directory is documentroot, which is located under "/ var/www/html"

The web pages that need to be published are usually placed in this directory. However, for ease of management and use, you can also modify the home directory path and change it to another directory. Such as:

Documentroot "/ var/www/html"

For example, you can set the apache server home directory path to "/ home/www" by changing the parameter value of the configuration parameter documentroot

Documentroot "/ home/www"

Set the default file

The default file refers to the web page that is displayed by entering the ip address or domain name of the web site in a web browser. That is, when the page to be visited is not specified in url, the default page displayed in the web browser, that is, the home page, is usually called index.html. In general, the default file name of apache is defined by the directoryindex configuration parameter. You can change the parameter value of directoryindex to another file:

Directoryindex index.html index.html.var

If you set multiple default files, the file names must be separated by spaces. Apache will look up the file name under the "home directory" path according to the order of the file name. If the first file can be found, the first file will be called, otherwise the second file will be found and called, and so on.

For example, to add index.html and index.jsp as default files, you can make the following changes:

Directoryindex index.html index.htm index.jsp index.html .var

Configure directory permissions

In the httpd.conf file, you can flexibly set the permissions of the directory. Is a container statement

It has to be in pairs. And encapsulate statements that set directory permissions, which only work on directories and their subdirectories. The following is an example of setting directory permissions in a httpd.conf file:

Options indexes multiviewsallowoverride noneorder allow,denyallow from all

Define catalog property options

In the statement, you can use options to define the properties of a directory, that is, to set which properties are used by a directory. These features include indexes, multiviews, and execcgl.

Indexes

The surface directory of this feature allows "directory browsing". When the customer specifies only the directory to access, when no specific file is specified to access the directory, and there are not only default files in that directory, apache will return a list of files and subdirectories in that directory as hypertext.

Muitiviews

This characteristic

Indicates that the directory allows content to match intelligently. This feature has some intelligence. When the object that the customer needs to access does not exist in the directory, apache will return the result of intelligent processing based on the content of the object accessed by the customer. For example, when a customer accesses http://192.168.0.2/icons/a", apache looks for all a.* files in the icons directory. If an a.gif file exists in this directory, apache returns the a.gif file to the client without an error message.

All

All contains all the features except multiviews. When there is no options in the container, the default value is all.

Execcgl

This feature indicates that cgl scripts are allowed to be executed in this directory.

Followsymlinks

This feature indicates that symbolic links are allowed in this directory.

.htaccess file

In the httpd.conf file, the default value of the configuration parameter accessfilename is .htaccess. Therefore, you can use the .htaccess file (access control file)

Set permissions for the directory.

Accessfilename .htaccess

The configuration parameter allowoverride can specify the type of instruction in the .htaccess file of the directory. These types include any combination of all, none and options, filelnfo, authconfig, and limit.

For security and efficiency reasons, although you can set directory access permissions through .htaccess files, you should avoid using .htaccess files as much as possible. Therefore, allowoverride is generally set to none, which prohibits the use of the settings in the .htaccess file:

Allowoverride none

When the allowoverride parameter value is all, the. Htaccess file can overwrite any previous configuration.

Implement access control

Directory access control can be achieved through allow and deny statements, and the order option is used to define the default access permissions and the order in which allow and deny statements are processed. The allow statement displays a list of hostnames that are allowed to access the directory, while the deny statement is followed by a list of hostnames that are denied access.

The allow and deny statements can be set for the client's domain name or ip address to feel which clients can access the server. Order statements are usually set to one of the following two situations

Order allow,deny or order deny,allow

Allow,deny: all clients are disabled by default, and the allow statement is matched before the deny statement. If a condition matches both the deny statement and the allow statement, the deny statement works (because the deny statement overrides the allow statement)

Deny,allow allows all clients to access by default, and deny statements are matched before allow statements. If a condition allows to match both the deny statement and the allow statement, the allow statement works (because the allow statement overrides the deny statement).

The following examples illustrate the use of order, allow, and deny statements.

The following statement indicates that access is allowed for all clients:

Order allow,deny

Allow from all

The following statement indicates that all clients are allowed access except from the client at www.deny.com and ip address 192.168.10.147

Order deny,allow

Deny from www.deny.com

Deny from 192.168.10.147

The following statement indicates that only clients from the 192.168.10ip segment are allowed to access

Order allow,deny

Allow from 192.168.10

The following statement indicates that access is only allowed from 24 clients on the network 192.168.10.max, except for the client with the ip address of 192.168.10.147

Order allow,deny

Allow from 192.168.10.0/24

Deny from 192.168.10.147

This is the end of the introduction on "the method of installing and setting up CentOS web server apache". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report