HTTP service setup and partial configuration in CentOS6 (1)

Source: Internet
Author: User
Tags connection reset fully qualified domain name

happy, Bo Master Harvest to the first comment, thank you lazy millet serious reading, will continue to work hard

recently, Bo Master learned about the HTTP service build, this time to introduce the construction of HTTP services and some related configuration

Lab Environment: CentOS6

The default HTTP version in CentOS6 is 2.2

Installation and startup of HTTP services

[email protected] ~]# rpm-ivh/misc/cd/packages/httpd-2.2.15-59.el6.centos.x86_64.rpm # #rpm安装方式: Install from cd, Ensures HTTP stability warning:/misc/cd/packages/httpd-2.2.15-59.el6.centos.x86_64.rpm:header V3 rsa/sha1 Signature, key ID C105b9de:nokeypreparing ########################################### [100%] 1:httpd # ########################################## [100%][[email protected] ~]# # # #成功安装

Files generated after installation:

[[email protected] ~]# ls /etc/rc.d/init.d/httpd      #服务脚本文件, Starting the service is starting it/etc/rc.d/init.d/httpd[[email protected] ~]# ls /etc/sysconfig/httpd       #服务脚本文件的配置文件, You can modify the operating mode of the HTTP Service/etc/sysconfig/httpd[[email protected] ~]# ls  /etc/httpd/conf/httpd.conf      #服务的主配置文件, can be configured to service, generally do not modify the main configuration file/etc/httpd/conf/ httpd.conf[[email protected] ~]# ls /etc/httpd/conf.d/*.conf      #服务的子配置文件, usually here to do the service configuration, do not modify the main configuration file, easy to modify and troubleshooting, note!!! Must end With. conf to be a configuration file/etc/httpd/conf.d/welcome.conf[[email protected] ~]# ls /var/www/html/       #站点网页页面的根目录, The default client access Site Directory a.jpg  http_group_file         image.html  secretbbs    http_user_passwd_file   index.html[[email protected] ~]# ls /etc/httpd/modules/      #服务模块文件, which is actually a soft connection of/usr/lib64/httpd/modules, can be viewed by LL command: ll /etc/httpd/mod_actions.so           mod_cgi.so            mod_mime.so...........mod_cgid.so              mod_mime_magic.so[[email protected] ~]# ls /etc/httpd/ logs/      Service log file, which is actually a soft connection of/var/log/httpd, can be viewed by LL command: Ll /etc/httpd/access_log   #访问日志       error_log  #错误日志

Control and startup of HTTP Services:

[[email protected] ~]# chkconfig httpd on/off #on: http service boot, off:http service boot does not start [[email protected] ~]# service httpd {star t/stop/restart/status/configtest/reload} #http服务的控制: start: startup service, restart: restart service, stop: stop service, status: service state, Configtest: configuration Syntax check, reload: overloaded config file, service does not restart

Simple little chestnut to protect you taichetaiwu:

[[email protected] ~]# service httpd start #开启服务Starting httpd:httpd:apr_sockaddr_info_get () failed for Centos6.9mag                                                           Edu.comhttpd:Could not reliably determine the server ' s fully qualified domain name, using 127.0.0.1 for ServerName [OK] #OK代表成功开启

Next you can go to the browser (recommended to use Firefox) to view the site page: the address bar input your virtual machine native IP can be accessed, the default interface, is the child configuration file/etc/httpd/conf.d/welcome.conf decision

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/21/9a3382c89820baf9415cfdfdf102fe59.jpg-wh_500x0-wm_3 -wmp_4-s_1370749326.jpg "title=" http.jpg "alt=" 9a3382c89820baf9415cfdfdf102fe59.jpg-wh_ "/>

We go to the Site page root directory to do Something:

[email protected] ~]# cd/var/www/html/#进入根目录 [[email protected] html]# vim index.html #编辑一个名为index. HTML file with the following Contents: & Lt;h1>centos6

Refresh the browser page, is not familiar with that interface (http Service supports HTML format files), understand what is the http service, ha haha

All right, mouse Pull Mu Yi--big head in the back, installation is very simple, mainly configuration drops

HTTP Service Common Configuration

Now that We've introduced the configuration, Let's start by understanding the composition of the main configuration file and the configuration format:

In the master configuration file, there are three types of configurations:

# # # section 1:global environment: Configuration of the Global environment

# # # 2: ' main ' server configuration: primary service configurations

# # # section 3:virtual hosts: virtual host-related configurations

Configuration format:Directive value

directive: instruction, case insensitive

value : A parameter that can be understood as an instruction

(1) Modify the format of the displayed server version information

[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 .... Servertokens OS #负责显示的服务器版本信息的格式, It is recommended to change to Servertokens Prod more secure .... Include conf.d/*.conf #解释了子配置文件的存在, where the child configuration file takes effect .... [email protected] conf.d]# Service httpd reload #重载配置文件 reloading Httpd:

Drawings: interpretation from the official format and examples

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/21/7c7d423d527335032d8f914659ce784f.jpg-wh_500x0-wm_3 -wmp_4-s_4084520748.jpg "title=" http4.jpg "alt=" 7c7d423d527335032d8f914659ce784f.jpg-wh_ "/>

So how do you view server version information?

Method 1: You can open a virtual machine to act as a customer client, using the command curl

[[email protected] ~] #curl-i 192.168.136.131 #选项-i, Display the response message header information http/1.1 okdate:sat, Oct 06:08:47 gmtserver : apache/2.2.15 (CentOS) #服务器版本信息Last-modified:sat, Oct 02:56:51 gmtetag: "60429-30-55c05bdb9fa40" Accept-rang es:bytescontent-length:48connection:closecontent-type:text/html; Charset=utf-8 #显示字符集, We can also modify the character set, which will be described later in this article

Method 2: view by Browser Tool:

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/21/2de82c5c8b274b1d7be9d024f8cf567f.jpg-wh_500x0-wm_3 -wmp_4-s_940000338.jpg "title=" http5.jpg "alt=" 2de82c5c8b274b1d7be9d024f8cf567f.jpg-wh_ "/>

(2) Modify the Listening IP and port

[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 ... #Listen 12.34.56.78:80listen #不写IP, default Listen to all the IP ports of this machine, can be modified to Listen 192.168.136.131:8000 specify IP and port, you can implement access control in small .... [email protected] conf.d]# Service httpd reload #重载配置文件 reloading Httpd:

Test with client or browser:

[[email protected] ~] #curl 192.168.136.131 #默认80端口curl: (Recv) failure:connection reset by Peer[[email protected] ~] #curl 192.168.136.131:8000 #指定8000端口 <H1>CENTOS6<H1><H2>CENTOS6<H2><H3>CENTOS6 

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/21/42934ccaba0a4df5ad3026bef647312e.jpg-wh_500x0-wm_3 -wmp_4-s_1528803886.jpg "title=" http6.jpg "alt=" 42934ccaba0a4df5ad3026bef647312e.jpg-wh_ "/>

(3) define the Site page root path:

[email protected] conf.d]# mkdir/app/site #创建新的根目录 [[email protected] conf.d]# mv/var/www/html/index.html/app/site/ #准备页面文件 [[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 .... DocumentRoot "/var/www/html" #默认根路径, can be modified to documentroot "/app/site" to modify the root path, access to find this path ....

(4) define the site main page:

[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 ... # same purpose, but it's much slower. #Direc Toryindex index.html Index.html.var #默认访问站点时访问的主页面, can be modified to DirectoryIndex index.txt index.html.var, etc...

(5) Setting the default character set

[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 .... Adddefaultcharset UTF-8 #默认UTF-8 Character set, You can modify the character set ....

(6) Define path aliases

[email protected] ~]# vim/etc/httpd/conf.d/mozart.conf #创建子配置文件 to. conf end alias "/bbs/" "/app/site/bbs/" #定义别名 in the format : Alias "URL" "/path/" note!!! The URL is a subdirectory under the default root directory, which is equivalent to the path/var/www/html/bbs/but not to the path, path is [[email protected] conf.d]# mkdir/var/www/html/bbs/[[email protected] conf.d]# Echo/var/www/html/bbs >/var/www/html/bbs/index.html[[email protected] conf.d]# mkdir/app/site /bbs[[email protected] conf.d]# echo/app/site/index.html >/app/site/bbs/index.html[[email protected] conf.d]# Service httpd Reload #重载配置文件Reloading httpd:

(7) Persistent Connection persistentconnection: The connection is established, each resource gets completed and does not disconnect, but continues to wait for other requests to complete, by default closing the persistent connection

[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 .... KeepAlive Off #默认关闭持久连接, can be modified to on, open persistent connection .... Maxkeepaliverequests #持久连接的最大连接资源数, The connection number to a certain value when disconnected .... KeepAliveTimeout #持久连接的最大持久时间, default unit is seconds

Test methods for persistent connections: impersonate a connection on a client

[[email protected] ~] #telnet 192.168.136.131 80Trying 192.168.136.131...Connected to 192.168.136.131.Escape character Is ' ^] '. get/index.html http/1.1 #模拟连接HOST: 192.168.136.131 #Web服务器HTTP/1.1 OK #回复的响应报文Date: Sat, Oct 2017 07:47 : gmtserver:apache/2.2.15 (CentOS) last-modified:sat, Oct 07:23:35 gmtetag: "60429-30-55c0977a92555" accept-ranges:bytescontent-length:48connection:closecontent-type:text/html; Charset=utf-8

(8) Log Settings

Logs are divided into: access logs and error logs

Error Log:

[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 ....  Errorlog Logs/error_log #错误日志路径, You can modify the default path # # Loglevel:control The number of messages logged to the error_log.# Possible Values include:debug, info, notice, warn, error, crit,# alert, emerg. #LogLevel warn #错误日志的级别, default to warn ....

Drawings: from the official website log level

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/21/74ae4ab845c7c4bb3ac96bcc4c1efda3.jpg-wh_500x0-wm_3 -wmp_4-s_3113611744.jpg "title=" http7.jpg "alt=" 74ae4ab845c7c4bb3ac96bcc4c1efda3.jpg-wh_ "/>

Emerg Emergency-system not Available. "child Cannot open lock File. Exiting "

Alert must take immediate action. "getpwuid:couldn ' t determine user name from uid"

Crit Fatal Condition. "socket:failed to get a socket, exiting child"

Error Condition. "premature End of script headers"

Warn warning Case. "child process 1234 do not exit, sending another SIGHUP"

Notice General Important Situation. "httpd:caught sigbus, attempting to dump core in ..."

Info General Information. "Server seems busy, (you could need to increase startservers, or min/maxspareservers) ..."

Debug error level Information "Opening config file ..."

To define the log format:

[email protected] conf.d]# vim/etc/httpd/conf/httpd.conf #编辑主配置文件 .... Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined #定义日志格式, commonly defined: Logformat "%h%l%u %t \ "%r\"%>s%b\ "%{referer}i\" \ "%{user-agent}i\" "combined .... Customlog Logs/access_log Combined #日志格式的使用 ....

Specific parameter definitions:

%H Client IP address%l remote user, enable Mod_ident is only valid, usually minus "-" "%u authentication (basic, digest) remote user, non-logon Access when a minus sign"-""%t the time when the server received the Request%r first line of RE quest, that is, the first line of the request message, the "method" of the request, the "URL" and the protocol Version%>s response Status code%b response message size, in bytes; not including the value of header "Referer" in the HTTP header%{referer}i request message of the response packet , that is, the hyperlink from which page jumps to the value of the header "user-agent" in The%{user-agent}i request message of the current page; the application that made the request

The above steps have been experimental success, (can exhausted me), well, Some configuration first introduced to this, the next time to introduce a few important configuration

that 's right! Almost forgot to check the configuration syntax command:

[[email protected] ~]# httpd-t #常用命令, CentOS7 http2.4 version also applies httpd:apr_sockaddr_info_get () failed for centos6.9magedu.c     Omhttpd:could not reliably determine the server ' s fully qualified domain name, using 127.0.0.1 for Servernamesyntax OK  #OK, the configuration syntax is correct [[email protected] ~]# service httpd configtest #适用于CentOS6上的配置语法检查命令httpd: apr_sockaddr_info_get () failed For centos6.9magedu.comhttpd:could not reliably determine the server ' s fully qualified domain name, using 127.0.0.1 for Servernamesyntax OK #OK, The configuration syntax is correct


This article is from the "Mozart" blog, make sure to keep this source http://mozart.blog.51cto.com/13286673/1975317

HTTP service setup and partial configuration in CentOS6 (1)

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.