httpd service to set up a simple web site deployment process, basic configuration of httpd server

One, web deployment process

First install the httpd service first, please refer to: https://blog.csdn.net/wulimingde/article/details/108322715

1. Determine the name and IP address of the website

To publish a website to the Internet, you first need to apply for a legal Internet address and register a complete website name with the DNS service provider. After meeting these requirements, you can deploy your own website on the Internet.

Suppose we want to build a web site on the server, the IP address is 20.0.0.55, and the name of the website is www.wlm.com to be used as our server.

If you want to visit our server on the client, you need the client to visit the wed site on the server through the address www.wlm.com in the browser. The client should have an available DNS domain name resolution service, which can resolve www.wlm.com to an IP address of 20.0.0.22.

On the web server side, set the IP address to 20.0.0.55 and the host name to www (can be set as required); modify the /etc/hosts file and add corresponding mapping records to improve local resolution speed.

[root@www ~]# vim /etc/hosts
20.0.0.55  www.wlm.com

2. Configure and start the httpd service

2.1, configure httpd service

Edit the main configuration file httpd.conf of the httpd service, find the configuration item "SeverName", and add a line of "ServiceName www.kgc.com" nearby to set the website name.

[root@www ~]# vi /usr/local/httpd/conf/httpd.conf
ServerName www.wlm.com

After each modification of the configuration content of the httpd.conf file, it is recommended to use the "apache -t or httpd -t" command to check the configuration content. If there is no syntax error, "Syntax OK" will be displayed. If there is an error, an error will be reported. You can modify the configuration file according to the error message.

[root@wode ~]# /usr/local/httpd/bin/apachectl -t
Syntax OK   //表示修改的配置格式没有错误
//我们之前把路径优化过可以直接使用命令
[root@wode ~]# apachectl -t
Syntax OK   
[root@wode ~]# httpd -t
Syntax OK    
2.2, start httpd service
[root@wode ~]# systemctl start httpd   //启动httpd服务
[root@wode ~]# netstat -aupt |grep httpd  //过滤httpd服务的网络连接状况
tcp6       0      0 [::]:http      [::]:*       LISTEN      9148/httpd 

3. Deploy web documents

The root directory of the website is located under /usr/local/httpd/htdocs, and you need to copy or upload the webpage documents to be published by the website to this directory. There is already a test webpage named index.html provided by the httpd server by default in this directory as the default homepage when visiting the website.

[root@wode ~]# cat /usr/local/httpd/htdocs/index.html   //产看默认网页的位置和显示内容
<html><body><h1>It works!</h1></body></html>

4. Visit the web site on the client

The client can access the httpd server through the domain name or IP address, and you will be able to see the page content of the web site. If you use the default homepage of the httpd service, the page will display "It works!", indicating that the httpd service has been used normally.
Note: It is recommended to use Google Chrome when the client visits
Insert picture description here

5. Check the access status of the web site

The httpd server uses two types of logs: access logs and error logs. The file names of these two types of logs are respectively accessed_log and error_log, located in the /usr/local/httpd/logs directory.
Check the access log file access_log, you can understand the web site access situation in time. A visit record corresponding to each row in the visit day records the client's IP address, the date and time of the visit to the server, and the requested web page object.

[root@wode ~]# tail /usr/local/httpd/logs/access_log   //查看访问日志文件
20.0.0.1 - - [01/Sep/2020:19:46:57 +0800] "GET / HTTP/1.1" 200 45   //访问记录
20.0.0.1 - - [01/Sep/2020:19:46:57 +0800] "GET /favicon.ico HTTP/1.1" 404 209

View the error log file error_log to provide a reference for troubleshooting server operation failures. Each line in the error log file corresponds to an error record, which records the date and time when the error occurred, the type of error event, and the description of the error event.

[root@wode ~]# tail /usr/local/httpd/logs/error_log   //查看错误访问日志文件
[Tue Sep 01 19:18:59.476349 2020] [mpm_event:notice]\
 [pid 52289:tid 139752290195264] AH00489: \
 Apache/2.4.29 (Unix) configured -- resuming normal operations   //错误访问记录
[Tue Sep 01 19:18:59.476454 2020] [core:notice] [pid 52289:tid \
139752290195264] AH00094: Command line: '/usr/local/httpd/bin/httpd'

The above are the basic steps for deploying a simple web site using httpd server. The httpd.conf configuration file involved in it has very few changes. It is very easy to build a simple web server.

Two, httpd.conf main configuration file analysis of httpd server

The main configuration file httpd.conf consists of two parts: comment line and setting line. Like most Linyx configuration files, the annotative text starts with "#" and contains an explanation of the relevant configuration content. The content other than the comment line and the blank line is the setting line, which constitutes the effective configuration of the web service. According to the different scope of the configuration, the setting line can be divided into global configuration and regional configuration.

1. Global configuration items

The global configuration determines the global operating parameters of the httpd server, and the configuration format is obtained using the "keyword value".

Each global configuration is an independent configuration and does not need to be included in this other task area.

The following lists some of the most commonly used global configuration items in the httpd.conf file.
ServerRoot “/usr/local/httpd”
Listen 80
User daemon
Group daemon
ServerAdmin
ServerName www.wlm.com
DocumentRoot “/usr/local/httpd/htdocs”
DirectoryIndex index.html index.php
ErrorLog logs/error log
LogLevel warn
CustomLog logs/ access log common
PidFile logs/httpd.pid
CharsetDefault UTF-8
lnclude confextra/httpd-default.conf
The specific meanings of these commonly used global configuration items are as follows:

  • ServerRoot: Set the root directory of the httpd server. This directory contains the necessary subdirectories and files to run the Web site. By default, the root directory of the httpd server is the installation directory of httpd.
    /usr /local/httpd: The same as the httpd installation directory specified when compiling and installing. In the httpd.conf configuration file, if an absolute path is not used when specifying a directory or file location, the directory or file location is considered to be under the root directory of the server.
  • Listen: Set the network port number that the httpd server listens to, the default is 80.
  • User: Set the user identity when running the httpd process, the default is daemon.
  • Group: Set the group identity when running the httpd process, the default is daemon.
  • ServerAdmin: Set the email address of the administrator of the httpd server, and you can contact the administrator of the Web site in time through this email address.
  • ServerName: Set the full host name of the Web site (host name + domain name).
  • DocumentRoot: Set the root directory of the website, that is, the actual storage path of web documents in the system. This configuration item is easier to confuse with ServerRoot and requires special attention.
  • Directorylndex: Set the default index page (home page) of the website, you can set multiple home page files, the home page files recognized by spaces are index, html.
  • ErrorLog: Set the path of the error log file, the default path is logs/error_log.
  • LogLevel: Set the log level, the default level is warn (warning).
  • CustomLog: Set the path to the log file. Log type, the default path is logs/access_log, and the type used is common (common format).
  • PidFile: Set the file used to save the httpd process number (PID), the default save address is logs/httpd.pid, and the logs directory is located in the root directory of the Apache server.
  • DefaultCharset: Set the default character set encoding used by web pages in the site, such as utf-8. gb2312, etc.
  • Include: Include the content of another configuration file, you can put the configuration of some special functions into a separate file, and then use the Include configuration item to include it in the httpd.conf file, which is convenient for independent maintenance of the configuration function. Does not affect the main configuration file.

2. Regional configuration items

In addition to the global configuration, most of the configurations in the httpd.conf file include those in this area. The area configuration uses a pair of combination marks to limit the scope of the configuration items. The common area configuration forms are as follows.

<Directory />    //定义"/"目录区域的开始
Options FollowSymLinks   //控制选项,允许使用符号链接
AllowOverride none   //不允许隐含控制文件中的覆盖配置
Require all denied      //禁止任何人访问此区域
</Directory>       //定义"/"目录区域的结束

In the above zone definition, a zone configuration of the root directory is set, and the added access control related configuration is only valid for the root directory, and will not affect the global or other directory zones. It should be noted that the root directory mentioned here refers to the root directory of the httpd server (the value set by ServerRoot), not the root directory of the CentOS system.

Guess you like

Origin blog.csdn.net/wulimingde/article/details/108365898