[Liunx] Deploy WEB service: Apache

[Liunx] Deploy WEB service: Apache

  • Overview
  • Apache
    • 1 Introduction
    • 2.Apache file path
    • 3.Apache detailed explanation
      • (1)Install Apache
      • (2) Start Apache
      • (3)Configuration file
        • a.Apache main configuration file: vim /etc/httpd/conf/httpd.conf information:
        • b. Virtual host based on host header
      • (4) Start demonstration:
        • a. Create two new website root directories
        • b. Create two new index.html in the root directories of the two websites respectively.
        • c. Create a new virtual machine configuration file
        • d. Restart the service
        • e. In order to resolve the local domain name of circle.com: you need to modify the named configuration file
        • f. Access the domain name we defined: the results are as follows

Overview

  • HTTP protocol, full name HyperText Transfer Protocol, Chinese name is Hypertext Transfer Protocol, is the most commonly used network protocol in the Internet. One of the important applications of HTTP is the WWW service. The original purpose of designing the HTTP protocol was to provide a method (request return) for publishing and receiving HTML (a page markup language) pages.
  • HTTP protocol is one of the commonly used communication protocols on the Internet. It has many applications, but the most popular one is used for communication between Web browsers and Web servers, that is, WWW applications or Web applications.
  • WWW, the full name is World Wide Web, often called Web, translated into Chinese as “World Wide Web”. It is currently the most popular form of information service among users on the Internet. The default port of the HTTP protocol WWW service application is 80 (the concept of port). The default port of another encrypted WWW service application https is 443, which is mainly used for online banking, payment and other money-related businesses. Today, the concepts of HTTP service, WWW service, and Web service have been confused, and they all refer to the most common website service applications.
    out

Apache

1. Introduction

  • Apache is the world’s number one web server software. It runs on all widely used computer platforms.
  • Apache originated from the NCSAhttpd server. After many modifications, it has become one of the most popular web server software in the world. Apache is taken from the pronunciation of “a patchy server”, which means a server full of patches. Because it is free software, people are constantly developing new functions and features for it, and modifying the original defects. Apache is characterized by simplicity, fast speed, stable performance, and can be used as a proxy server.

2.Apache file path

  • Package name: httpd
  • Default web directory: /var/www/html
  • Configuration file home directory: /etc/httpd/
  • Main configuration file: /etc/httpd/conf/httpd.conf

3.Apache detailed explanation

(1)Install Apache

yum install -y httpd

(2)Start Apache

systemctl start httpd

As shown in the figure: Proves that Apache has started normally

(3)Configuration file

a.Apache main configuration file: vim /etc/httpd/conf/httpd.conf information:
ServerRoot "/etc/httpd" //The path to the server installation
Listen 80 //Listen port
Include conf.modules.d/*.conf //Reference the .conf module configuration file under conf.modules.d
User apache //Run user apache
Group apache //Run user group
ServerAdmin root@localhost //The email address sent if there is an error in running Apache
<Directory /> //Project root directory, access to the root directory is denied
    AllowOverride none
    Require all denied
</Directory>
DocumentRoot "/var/www/html" //Website home directory
<Directory "/var/www"> // /var/www allows access
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks //Run using connections, etc.
    AllowOverride None
    Require all granted
</Directory>
<IfModule dir_module>
    DirectoryIndex index.html //Default access page index.html
</IfModule>
<Files ".ht*">
    Require all denied //disable
</Files>
ErrorLog "logs/error_log" //Error log
LogLevel warn //warning level
<IfModule log_config_module> //Log format
    LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i "" combined
    LogFormat "%h %l %u %t "%r" %>s %b" common
    <IfModule logoo_module>
      LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i " %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
<IfModule mime_module> //Run file type
    TypesConfig /etc/mime.type
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8 //Default encoding

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf //Introduce all .conf files in conf.d/
</code><img class="look-more-preCode contentImg-no-view" src="//i2.wp.com/csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack. png" alt="" title="">
b. Virtual host based on host header
<VirtualHost *:custom port>
ServerName www.circle.com #Add your website name after ServerName
ServerAdmin [email protected] #Add the email address of the website administrator after ServerAdmin so that others can contact the website administrator if they have any questions.
DocumentRoot /var/www/html #Add the directory path to store website content after DocumentRoot (user's personal directory)
</VirtualHost>

(4) Start demonstration:

a. Create two new website root directories
[root@server1 conf.d]# mkdir /var/www/html/web{1,2}
[root@server1 conf.d]# cd /var/www/html/
[root@server1 html]# ls -l
Total usage 0
drwxr-xr-x 2 root root 101 August 2 14:12 exam
drwxr-xr-x 2 root root 6 November 14 06:34 web1
drwxr-xr-x 2 root root 6 November 14 06:34 web2
b. Create two new index.html in the root directories of the two websites
[root@server1 html]# vi web1/index.html
[root@server1 html]# vi web2/index.html
[root@server1 html]#ls web1
index.html
[root@server1 html]#ls web2
index.html
c. Create a new virtual machine configuration file
[root@server1 html]# cd /etc/httpd/conf.d/
[root@server1 conf.d]# vi web1.conf
[root@server1 conf.d]# vi web2.conf
[root@server1 conf.d]# cat web1.conf
<VirtualHost 192.168.122.1:80>
ServerName www.circle.com
ServerAdmin [email protected]
DocumentRoot /var/www/html/web1
</VirtualHost>
[root@server1 conf.d]# cat web2.conf
<VirtualHost 192.168.122.1:80>
        ServerName admin.circle.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/html/web2
</VirtualHost>
d. Restart the service
systemctl restart httpd
e. In order to resolve the local domain name of circle.com: you need to modify the named configuration file
vi /etc/named.conf

The modified file content is as follows

[root@server1 named]# cat /etc/named.conf
options {<!-- -->
listen-on port 53 {<!-- --> 192.168.122.1; };
directory "/var/named";
allow-query {<!-- --> any; };
};

zone "uos.com" IN {<!-- -->
type master;
file "uos.com.db";
};

zone "circle.com" IN {<!-- -->
        type master;
        file "circle.com.db";
};

zone "." IN {<!-- -->
type hint;
file "named.ca";
};

</code><img class="look-more-preCode contentImg-no-view" src="//i2.wp.com/csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack. png" alt="" title="">
[root@server1 named]# cp -p uos.com.db circle.com.db
[root@server1 named]# ls -l
Total usage 28
-rw-r----- 1 root named 246 November 13 16:29 circle.com.db
drwxrwx--- 2 named named 6 October 12 2022 data
drwxrwx--- 2 named named 6 October 12 2022 dynamic
-rw-r----- 1 root named 2253 October 12 2022 named.ca
-rw-r----- 1 root named 152 October 12 2022 named.empty
-rw-r----- 1 root named 152 October 12 2022 named.localhost
-rw-r----- 1 root named 168 October 12 2022 named.loopback
drwxrwx--- 2 named named 6 October 12 2022 slaves
-rw-r----- 1 root named 246 November 13 16:29 uos.com.db
-rw-r----- 1 root named 238 November 13 16:07 uos.com.files
[root@server1 named]# vi circle.com.db
[root@server1 named]# cat circle.com.db
$TTL 1D
@ IN SOA ns.circle.com root.ns.circle.com. (
0;serial
1D; refresh
1H; retry
1W; expire
3H ) ;minimum
IN NS ns.circle.com.
ns IN A 192.168.122.1
www IN A 192.168.122.1
admin IN A 192.168.122.1
oa IN A 192.168.122.1
[root@server1 named]# systemctl restart named

</code><img class="look-more-preCode contentImg-no-view" src="//i2.wp.com/csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreBlack. png" alt="" title="">
f. Visit the domain name we defined: the results are as follows
[root@server1 named]# curl www.circle.com
this is web1;
[root@server1 named]# curl admin.circle.com
this is web2;
[root@server1 named]#