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

Apache-2.2.32 installation configuration

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Apache-2.2.32 installation configuration

I. Apache service installation

1. Create a directory and download the Apache source code package

[root@apache] # mkdir/home/wangning/tools-p

[root@apache ~] # cd/home/wangning/tools

[root@apache tools] # wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.32.tar.gz

two。 Unpack and install Apache

[root@apache tools] # tar zxvfhttpd-2.2.32.tar.gz

[root@apache tools] # cdhttpd-2.2.32

[root@apache httpd-2.2.32] # yum-y install zlib zlib-devel # install zlib dependency package

[root@apache httpd-2.2.32] # / configure-- prefix=/application/apache2.2.32-- enable-deflate-- enable-expires--enable-headers-- enable-modules=most-- enable-so-- with-mpm=worker--enable-rewrite

[root@apache httpd-2.2.32] # make

[root@apache httpd-2.2.32] # make install

[root@apache httpd-2.2.32] # ln-s / application/apache2.2.32//application/apache

3. Check the syntax, start the Apache service, two ways to start

[root@apache httpd-2.2.32] # / application/apache/bin/apachectl-t

[root@apache httpd-2.2.32] # / application/apache/bin/apachectl start # start the Apache service

Httpd: apr_sockaddr_info_get () failed for apache (error 1)

Httpd: Could not reliablydetermine the server's fully qualified domain name, using 127.0.0.1 forServerName (error 2)

[root@apache httpd-2.2.32] # / application/apache/bin/httpd-k start # start the Apache service

Add × × part to the hosts file to eliminate the error.

[root@apache ~] # cat / etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4

:: 1 localhost localhost.localdomainlocalhost6 localhost6.localdomain6

10.0.0.20 apache

Add × × part to the configuration file to eliminate error 2.

[root@apache ~] # grepServerName / application/apache/conf/httpd.conf

# ServerName gives the name andport that the server uses to identify itself.

# ServerName www.example.com:80

ServerName 127.0.0.1:80

4. Check whether the Apache service starts properly

[root@apache httpd-2.2.32] # lsof-iRU 80

[root@apache httpd-2.2.32] # ps-ef | grep httpd

[root@apache httpd-2.2.32] # curl 127.0.0.1 # Test whether the browser can access

Itworks!

Second, the home page, structure directory and virtual host configuration of the Apache server

1. The directory where the default home page is located, and the default home page is index.html

[root@apache htdocs] # pwd

/ application/apache/htdocs

two。 Change the default home page to wangning.html, and × × is the added content.

[root@apache conf] # grepDirectoryIndex / application/apache/conf/httpd.conf

# DirectoryIndex: sets the filethat Apache will serve if a directory

DirectoryIndex wangning.html index.html

[root@apache htdocs] # touch/application/apache/htdocs/wangning.html

[root@apache htdocs] # echo "www.wangning.com" > / application/apache/htdocs/wangning.html

[root@apache htdocs] # ls/application/apache/htdocs

Index.html wangning.html

[root@apache htdocs] # / application/apache/bin/apachectl-t

[root@apache htdocs] # / application/apache/bin/apachectl graceful

[root@apache htdocs] # curl10.0.0.20 # the test modified the home page successfully

Www.wangning.com

3. When the default home page does not exist, the Apache service displays the directory structure on the browser page by default

[root@apache htdocs] # cd/application/apache/htdocs/

[root@apache htdocs] # mv index.htmlindex.html.bak

Enter the Apache server address in the browser, which displays the directory structure by default

Add a minus sign before Indexes in the configuration file, or delete Indexex, and the directory structure will not be displayed.

[root@apache htdocs] # grep-B 13 "Options Indexes FollowSymLinks" / application/apache/conf/httpd.conf

#

# Possible values for the Options directiveare "None", "All"

# or any combination of:

# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

#

# Note that "MultiViews" must benamed * explicitly*-"Options All"

# doesn't give it to you.

#

# The Options directive is both complicatedand important. Please see

# http://httpd.apache.org/docs/2.2/mod/core.html#options

# for more information.

#

Options-Indexes FollowSymLinks

[root@apache htdocs] # / application/apache/bin/apachectl-t

[root@apache htdocs] # / application/apache/bin/apachectl graceful

So that the directory structure is not displayed.

4. Configure virtual hosts for Apache servers (based on domain name, port number, ip)

1) the basic information is as follows

domain name

Site directory

Www.wangning.com

/ var/html/www

Bbs.wangning.com

/ var/html/bbs

Blog.wangning.com

/ var/html/blog

2) create a site directory

[root@apache /] # mkdir/var/html/ {www,bbs,blog}-p

[root@apache /] # for n in wwwbbs blog;do echo "http://$n.wangning.com">/var/html/$n/index.html;done # # create an index.html file in each of these three directories and write to three URLs

[root@apache /] # for n in wwwbbs blog;do cat / var/html/$n/index.html;done

Http://www.wangning.com

Http://bbs.wangning.com

Http://blog.wangning.com

3) add the following at the end of the virtual host configuration file and delete the two default virtual host samples from the file

[root@apache /] # cat/application/apache/conf/extra/httpd-vhosts.conf

ServerAdmin 1198143315@qq.com

DocumentRoot "/ var/html/www"

ServerName www.wangning.com

ServerAlias wangning.com

ErrorLog "logs/www-error_log"

CustomLog "logs/www-access_log" common

ServerAdmin 1198143315@qq.com

DocumentRoot "/ var/html/bbs"

ServerName bbs.wangning.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" common

ServerAdmin 1198143315@qq.com

DocumentRoot "/ var/html/blog"

ServerName blog.wangning.com

ErrorLog "logs/blog-error_log"

CustomLog "logs/blog-access_log" common

4) configure the main configuration file httpd.conf of Apache to remove the pound sign before the × × part of the content.

[root@apache /] # egrep-C1 "Virtualhosts | httpd-mpm.conf" / application/apache/conf/httpd.conf

# Server-pool management (MPMspecific)

Include conf/extra/httpd-mpm.conf

--

# Virtual hosts

Include conf/extra/httpd-vhosts.conf

Add the following at the end of the Apache main configuration file httpd.conf

Options-Indexes FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

[root@apache /] # / application/apache/bin/apachectl-t

[root@apache /] # / application/apache/bin/apachectl graceful

5) configure Linux and windows local hosts files

Hosts file for linux

[root@apache /] # cat / etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4

:: 1 localhost localhost.localdomainlocalhost6 localhost6.localdomain6

10.0.0.20 apache

10.0.0.20 www.wangning.com bbs.wangning.com blog.wangning.com

Windows's C:\ Windows\ System32\ drivers\ etc\ hosts file

# localhost name resolution ishandled within DNS itself.

# 127.0.0.1 localhost

#:: 1 localhost

10.0.0.20 www.wangning.com bbs.wangning.comblog.wangning.com

6) finally, visit the three domain names in the browser of windows, and the result is ^ * ^.

III. Log format configuration of Apache server

1. There are two log formats:

Common Log format (CommonLog Format)

Combined log format (CombinedLog Format)

The default is a common format, and it is customary to use combined logs in general work.

two。 Set the log format of three virtual hosts to combined mode

Just change all common in httpd-vhosts.conf to combined.

[root@apache ~] # cat / application/apache/conf/extra/httpd-vhosts.conf

ServerAdmin 1198143315@qq.com

DocumentRoot "/ var/html/www"

ServerName www.wangning.com

ServerAlias wangning.com

ErrorLog "logs/www-error_log"

CustomLog "logs/www-access_log" combined

ServerAdmin 1198143315@qq.com

DocumentRoot "/ var/html/bbs"

ServerName bbs.wangning.com

ErrorLog "logs/bbs-error_log"

CustomLog "logs/bbs-access_log" combined

ServerAdmin 1198143315@qq.com

DocumentRoot "/ var/html/blog"

ServerName blog.wangning.com

ErrorLog "logs/blog-error_log"

CustomLog "logs/blog-access_log" combined

4. Log polling configuration of Apache server

There are two kinds of 1.Apache log polling tools, one is the polling tool rotatelog that comes with Apache, and the other is the third-party log polling tool cronolog. In general, we have lost logs before using the rotatelog tool that comes with the third-party tool cronolog,Apache, so we continue to use the third-party cronolog log tool all the time.

two。 Download and compile the installation log polling cronolog tool

[root@apache tools] # wget http://down1.chinaunix.net/distfiles/cronolog-1.6.2.tar.gz

[root@apache tools] # tar zxvfcronolog-1.6.2.tar.g

[root@apache tools] # cdcronolog-1.6.2

[root@apache cronolog-1.6.2] #. / configure

[root@apache cronolog-1.6.2] # make

[root@apache cronolog-1.6.2] # make install

A cronolog command will be generated after installation

[root@apache cronolog-1.6.2] # ls / usr/local/sbin/cronolog

/ usr/local/sbin/cronolog

3. Configure the httpd-vhosts.conf file, take the blog.wangning.com virtual host as an example, and let the access_log log poll (note that the log path should be written in an absolute path)

[root@apache /] # cat/application/apache/conf/extra/httpd-vhosts.conf

ServerAdmin 1198143315@qq.com

DocumentRoot "/ var/html/blog"

ServerName blog.wangning.com

ErrorLog "logs/blog-error_log"

CustomLog "| / usr/local/sbin/cronologapp/logs/blog-access_%Y%m%d.log" combined

[root@apache /] # ls / app/logs/ # shows that the configuration is successful

Blog-access_20170528.log blog-access_20170627.log

Version number hidden configuration of Apache server

1. Change full to Prod,on to off

[root@apache ~] # egrep "ServerTokens | ServerSignature" / application/apache/conf/extra/httpd-default.conf

# ServerTokens

ServerTokens Prod

ServerSignature off

two。 Remove the note pound sign in front of the line

[root@apache ~] # grep "Includeconf/extra/httpd-default.conf" / application/apache2.2.32/conf/httpd.conf

Include conf/extra/httpd-default.conf

3. Check the syntax, reload the Apache service, the test has no version number

[root@apache] # / application/apache/bin/apachectl-t

[root@apache ~] # / application/apache/bin/apachectl graceful

[root@apache ~] # curl-Iwww.wangning.com

HTTP/1.1 200 OK

Date: Tue, 27 Jun 2017 14:24:45GMT

Server: Apache

Last-Modified: Sat, 27 May 201715:52:29 GMT

ETag: "82fa4-18-5508370f3e458"

Accept-Ranges: bytes

Content-Length: 24

Content-Type: text/html

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

Servers

Wechat

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

12
Report