Linux CentOS7 Web Services

Web Services

Web service is one of the most popular and popular services for Internet applications. It is a platform for information release, data query, data processing, network office and distance education.

1, Introduction to Web Services

Web server, also known as WWW server, is mainly used to provide online information browsing services. Www stands for the world wide web. WWW is a multimedia information query tool on the Internet. Originated in March 1989, it is a master-slave distributed hypermedia system developed by the European Laboratory for Particle Physics (CERN). Through the world wide web, as long as people use simple methods, they can access rich information quickly and conveniently.

Currently, there are several commonly used Web servers:

1,Microsoft IIS

IIS (Internet Information Services) is a basic Internet service based on Windows platform provided by Microsoft. It is one of the popular Web server products.

2,IBM WebSphere

Websphere application server is a fully functional and open WEB application server launched by IBM, which is based on Java application environment.

3,Apache

Apache (Apache HTTP Server) is an open source Web server software, which can run in most operating systems. It is widely used because of its multi platform and security. It is fast and reliable, and can be expanded through simple API to compile interpreters such as Perl/Python into the server. It is one of the popular Web server products.

4,Tomcat

Tomcat server is a free open source web application server. It is a lightweight application server. It is widely used in small and medium-sized systems and when there are not many concurrent access users. It is the first choice for developing and debugging JSP programs. For a beginner, you can think that when Apache server is configured on a machine, you can use it to respond to the access request of HTML page. In fact, Tomcat is an extension of Apache server, but it runs independently at runtime, so when you run tomcat, it actually runs separately as a process independent of Apache. Because Tomcat technology is advanced, stable and free, it is loved by Java enthusiasts and has been recognized by some software developers. It has become a popular Web application server.

5,Nginx

Nginx (engine x) is a high-performance HTTP and reverse proxy Web server. It also provides IMAP/POP3/SMTP services. Nginx is a lightweight Web server / reverse proxy server and e-mail (IMAP/POP3) proxy server, which is distributed under BSD like protocol. It is characterized by less memory and strong concurrency. In fact, nginx's concurrency is better in the same type of Web server. It is famous for its stability, rich function set, simple configuration file and low consumption of system resources. It is one of the popular Web server software at present.

2, Apache overview

Apache is an open source Web server software. Because of its good cross platform and security characteristics, it is almost the only Web server software selected by mainstream Unix, Linux and BSD systems (such as FreeBSD).

Apache server has the following features:

(1) Simple, fast, stable and configurable.

(2) Static and dynamic content support. Apache supports both static and dynamic content. Dynamic content is provided by a set of related technologies, including SSI, CGI, PHP, Perl and main server API.

(3) Module support. Apache server can be extended dynamically in a modular way. The software module can be directly connected to the core server program or dynamically loaded into the server as needed.

(4) Support SSL and virtual host. Adopt the technology and concept of virtual host based on host name or IP address, use single or multiple IP addresses to support multiple websites at the same time, and use SSL to support HTTPS at the same time.

(5) Log. Apache has a complete logging function, can define the level of information recording, and can record the client's request and the corresponding information of the server in detail in the log file. It is convenient for administrators to analyze log files with special programs and collect server usage statistics.

(6) Support user authentication mechanism. Before accessing important resources, you need to pass user and password authentication.

3, Apache service practices

Case 1:

A company has purchased a new server with Linux operating system installed on it. Now it is required to configure the server as an Apache server to provide basic Web services for the company's employees. Specific requirements are as follows:

(1) Enable the root directory of the default WEB service / var/www/html, and the default home page is index HTML with the content "Welcome to" www.test.com ”, accessible using both IP address and domain name.

(2) Create a virtual directory named / vfolder in the Apache server. Its corresponding physical path is / var/tfolder. The default home page of the virtual directory is default HTML with the content "Welcome to" www.test.com/vfolder".

(1) Enable the root directory of the default WEB service / var/www/html, and the default home page is index HTML with the content "Welcome to" www.test.com ”, accessible using both IP address and domain name.

1. Experimental environment

rolehost nameoperating systemnetwork cardIP addressremarks
web serverwebserver.gc.comCentOS7.4vmnet1 (host only)192.168.92.11virtual machine
web client webclient.gc.comCentOS7.4vmnet1 (host only)192.168.92.101virtual machine

2. Environmental preparation

  • web server

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.92.11
NETMASK=255.255.255.0
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens32
DEVICE=ens32
ONBOOT=yes
​
[root@localhost ~]# hostnamectl set-hostname webserver.gc.com
[root@localhost ~]# hostname
webserver.gc.com
​
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
​
[root@webserver ~]# getenforce 
Disabled
​
[root@webserver ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                          repo name                      status
dvd                              gc                             enabled: 3,894
repolist: 3,894
  • web client

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens32
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.92.101
NETMASK=255.255.255.0
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
NAME=ens32
DEVICE=ens32
ONBOOT=yes
​
[root@localhost ~]# hostnamectl set-hostname webclient.gc.com
[root@localhost ~]# hostname
webclient.gc.com
​
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
​
[root@webserver ~]# getenforce 
Disabled
​
[root@webserver ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                          repo name                      status
dvd                              gc                             enabled: 3,894
repolist: 3,894

3. Profile resolution

/etc/httpd/conf/httpd.conf              ###Master profile
/usr/sbin/httpd                         ###Binary execution script
/var/log/httpd                          ###log file
/var/www/html                           ###Site root
/etc/httpd/conf.d/*.conf                ###Sub profile
/usr/lib64/httpd/ modules/              ###Module profile
/var/www/error/                         ###Page error page file
/usr/lib/systemd/system/httpd.service   ###Service management script

4. Service configuration

(1) . install software package

[root@webserver ~]# yum install vim httpd -y

(2) Create homepage content

[root@webserver ~]# echo "welcome to www.test.com" >> /var/www/html/index.html
[root@webserver ~]# cat /var/www/html/index.html 
welcome to www.test.com

(3) . start the service and set the startup self startup

[root@webserver ~]# systemctl start httpd
[root@webserver ~]# systemctl enable httpd

5. Client test

(1) Install and test software package

[root@webclient ~]# yum install elinks -y

(2) . modify the region resolution file

[root@webclient ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.92.11   www.test.com

(3) . access test

[root@webclient ~]# curl http://192.168.92.11
welcome to www.test.com
[root@webclient ~]# elinks --dump http://www.test.com
   welcome to www.test.com

(2) Create a virtual directory named / vfolder in the Apache server. Its corresponding physical path is / var/tfolder. The default home page of the virtual directory is default HTML with the content "Welcome to" www.test.com/vfolder".

6. Service configuration

(1) , create table of contents and home page

[root@webclient ~]# mkdir /var/tfolder
[root@webclient ~]# echo "welcome to www.test.com/vfolder" >> /var/tfolder/default.html
[root@webclient ~]# cat /var/tfolder/default.html 
welcome to www.test.com/vfolder

(2) . modify the configuration file

[root@webserver ~]# cat /etc/httpd/conf/httpd.conf
ServerName www.test.com:80
<Directory "/var/tfolder">
    AllowOverride None
    Require all granted
    Options None
</Directory>
<IfModule dir_module>
    DirectoryIndex index.html default.html
</IfModule>
<IfModule alias_module>
    Alias /vfolder "/var/tfolder"
</IfModule>

(3) . restart the service

[root@webserver ~]# systemctl restart httpd

7. Client test

  • Access test

[root@webclient ~]# curl http://192.168.92.11/vfolder/
welcome to www.test.com/vfolder
[root@webclient ~]# elinks --dump http://www.test.com/vfolder
   welcome to www.test.com/vfolder

Keywords: Linux Operation & Maintenance Apache server

Added by nerya on Thu, 24 Feb 2022 06:42:37 +0200