httpd Configuration of CentOS 6.7

Source: Internet
Author: User

Objective:

Location of HTTP in the OSI:

In the OSI seven-tier model, HTTP (Hyper Text Tranfer protocol) is located on the seventh tier of the application layer, a protocol that is local to the network host connection, partly based on the TCP protocol at the fourth Transport layer (and the UDP protocol). The TCP protocol is also the IP protocol based on the third layer network layer.


The relationship between HTTP and httpd

The Web server that implements the HTTPD application protocol now has three main mainstream:

HTTPD, also known as the main program in the Apache service

Ngnix

Lighttpd


-------------------------Split Line--------------------------


CentOS 6 Default httpd version 2.2, CentOS 7 default httpd version 2.4


First, the installation of httpd

Yum-y Install httpd

A. By RPM-QL httpd command you can observe

1. configuration file:/etc/httpd/conf/httpd.conf

Among the additional profiles directory:/etc/httpd/conf.d/*.conf, suitable for configuring virtual host, etc.

2. Program Files:/usr/sbin/httpd

3. log file:/var/log/httpd

4. module file:/usr/lib64/httpd/modules

B.HTTPD Service-related status and activation

Service httpd start//start httpd Services

Service httpd restart//restart HTTPD services

Service httpd reload//Reread httpd services Configuration

Chkconfig httpd On|off//power on or off httpd service


Second, the basic configuration of httpd

A. Monitoring port modification

1.vim/etc/httpd/conf/httpd.conf

2. Search Listen

3. Modify the format listen [IP:] PORT

4. Example: Listen 172.16.45.67:8080

5.HTTPD-T Check Syntax

6.service httpd Reload|restart

Note: In the listen if you want to add IP, you must be a native IP

After modifying the IP, be sure to service restart

Two different IPs cannot appear on the same port


B.dso:dynamic shared objects Dynamic sharing module

1.vim/etc/httpd/conf/httpd.conf

2. Search LoadModule

3. Non-required modules can be commented

4. Module switching: Modify the httpd value in the/ETC/SYSCONFIG/HTTPD

Httpd=/usr/sbin/httpd|httpd.worker|httpd.event

5. View the static compilation module: Httpd-l


C. Site access control

1. IP address-based access control

Vim/etc/httpd/conf/httpd.conf

Search DocumentRoot Find root directory

Then add the following code

<directory "Path/to/some_dir" >//path path to root address order Allow,deny allow from 172.16 deny from 172.16.45.7 2 Deny from all</directory>

Where the IP source request is followed by the best matching rule mechanism

If the above instance: 172.16.45.72 is inaccessible,

172.16.45.01 can access

192.168.1.10 not accessible

2. Control based on file system and user

Vim/etc/httpd/conf/httpd.conf

Search DocumentRoot Find root directory

Then add the following code

<directory "/path/to/some_dir" > Options none allowoverride none authtype Basic authname "Some_string_her E "//information displayed to the user AuthUserFile"/path/to/ht_passwd_file "//authuserfile"/etc/httpd/conf/.htpasswd "Require user u Ser1 user2 ...//You can also use require Valid-user to indicate that all users are legitimate </Directory>

Where the user password can be generated using the HTPASSWD command

htpasswd [Options]/path/to/ht_passwd_file USERNAME

3. Control based on group account

Set the same user account settings, but added control of the group in the Code

<directory "/path/to/some_dir" > Options none allowoverride none authtype Basic authname "Some_string_her E "AuthUserFile"/path/to/ht_passwd_file "AuthGroupFile"/path/to/ht_group-file "//authgroupfile"/etc/httpd/conf /.groupwd "//Then write mygroup:user1 user2 Require group Grp1 grp2 in/etc/httpd/conf/.groupwd ...//grp1 fill in Mygro Up, consistent with the name of the content in the above file </Directory>


D. Defining a site Alias

Vim/etc/httpd/conf/httpd.conf

Alias definition Format: alias/url/"/path/to/some_dir/"

Example: alias/images/"/var/www/html/pictures/"

where "/var/www/html" is the DocumentRoot value


Note: Where images is not a specific directory for the system, that is,/var/www/html/pictures/there is a logo.jpg file, use 172.16.45.67/images/ Logo.jpg can access the file, images is equivalent to/var/www/html/pictures


E. Log Settings

Log format: Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined

%h:remote host%l:remote logname (from Identd)%u:remote user (from auth)%t:time the request was received (Stand 中文版 forma T) "%r": First line request%s:status code to request tha got internally redirected%b:size of response in Bytes,excluding HT TP headers "%{referer}i": the contents of the Referer header line (s) in the request sent to the server//sent to the server for the header of the requested referrer Content I represents the value "%{user-agent}i": the contents of User-agent header line (s) in the request sent to the server/client browser type


F. Virtual Host Settings

Virtual host settings useful: IP based, port based, FQDN based, three kinds of settings basically similar

This article takes an IP-based example:

1.VIM/ETC/HTTPD/CONF.D/VHOST1.CONF//Not directly modified in conf/httpd.conf

Modify the Namevirtualhost value, where the IP listener address is the native address

2. Add the following code to the vhost1.conf

<virtualhost 172.16.45.71:80> ServerName www1.magedu.com documentroot/tmp/vhosts/www1</virtualhost>

Add index.html to the/TMP/VHOST/WWW1 folder and write to the content, access 172.16.45.71 to see the content








Exercise: Write a script that generates 10 FQDN virtual host configurations in bulk:

     require configuration file to be/etc/httpd/conf.d/virhost#.conf

#/bin/bash# #Ip =$ (ifconfig | head -n 3 | grep  "Inet addr"  |  awk -f:  ' {print $2} ' | awk  ' {print $1} ')     //extract native Ipecho   "your ip is  $Ip" cp /etc/httpd/conf/httpd.conf{,.bak}    // Backup httpd configuration file sed -i  "[email protected]*\<namevirtualhost\>.* @NameVirtualHost   $IP: [ Email protected] " /etc/httpd/conf/httpd.conf    //change namevirtualhost value, Enable virtual host VirtualHost ()  {    echo  <VirtualHost  $Ip:80>  >/etc/ httpd/conf.d/virhost$1.conf    echo -e  "\tservername www$1.chunlanyy.com"  >>/etc/httpd/conf.d/virhost$1.conf    echo -e  "\tdocumentroot / Tmp/virhost/www$1 " >>/etc/httpd/conf.d/virhost$1.conf    mkdir -p / Tmp/vhost/www$1    echo  "</VirtualHost>"  >>/etc/httpd/conf.d/virhost$1.conf}      The    //function writes the configuration file Hostfile () {    mkdir -p /tmp/virhost/www$1/     touch /tmp/virhost/www$1/index.html    echo  "


Modify the/etc/hosts content of the 172.16.45.72 host

172.16.45.67 www1.chunlanyy.com

172.16.45.67 www2.chunlanyy.com

...

10 names are written in turn

And then use the 172.16.45.72 host for access, the results are as follows

[Email protected] tmp]# Curl WWW{1..10}.CHUNLANYY.COM<H1>WWW1 site


This article from "An Idle youth, life in the mainland" blog, please be sure to keep this source http://mghuee.blog.51cto.com/11643000/1825878

httpd Configuration of CentOS 6.7

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.