HTTP server setup

Posted by toxictoad on Sun, 26 Dec 2021 04:49:29 +0100

Description of experimental environment

Host systemSystem versionIP address
ServerLinuxRHEL 7.0192.168.43.128/24
clientLinuxRHEL 7.4192.168.43.15/24
clientWindows 11Windows 11192.168.43.1/24

Server configuration

Download and install HTTP services

  • Download and install Apache
[root@Server ~]# yum -y install httpd
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Base                                                  | 4.1 kB     00:00     
(1/2): Base/group_gz                                    | 137 kB   00:00     
(2/2): Base/primary_db                                  | 4.0 MB   00:00     
Resolving Dependencies

...

Installed:
  httpd.x86_64 0:2.4.6-67.el7                                                

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                apr-util.x86_64 0:1.5.2-6.el7      
  httpd-tools.x86_64 0:2.4.6-67.el7       mailcap.noarch 0:2.1.41-2.el7      

Complete!
[root@Server ~]# 
  • Firewall release HTTP service
[root@Server conf]# firewall-cmd --list-all
public (default, active)
  interfaces: eno16777736
  sources: 
  services: dhcp dhcpv6-client samba ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@Server conf]# Firewall CMD -- permanent -- add service = "HTTP" / / firewall release service
success
[root@Server conf]# Firewall CMD -- reload / / reload firewall rules
success
[root@Server conf]# Firewall CMD -- list all / / lists the release list of firewalls
public (default, active)
  interfaces: eno16777736
  sources: 
  services: dhcp dhcpv6-client http samba ssh
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@Server conf]# 
  • Set the HTTP service to start automatically and start the HTTP service
[root@Server conf]# systemctl enable httpd / / set boot auto start
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[root@Server conf]# systemctl restart httpd / / restart the HTTP service
[root@Server conf]# systemctl status httpd / / view the HTTP service status
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since Fri 2021-12-24 10:31:41 CST; 10s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 5230 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 5274 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─5274 /usr/sbin/httpd -DFOREGROUND
           ├─5275 /usr/sbin/httpd -DFOREGROUND
           ├─5276 /usr/sbin/httpd -DFOREGROUND
           ├─5277 /usr/sbin/httpd -DFOREGROUND
           ├─5278 /usr/sbin/httpd -DFOREGROUND
           └─5279 /usr/sbin/httpd -DFOREGROUND

Dec 24 10:31:21 Server systemd[1]: Starting The Apache HTTP Server...
Dec 24 10:31:31 Server httpd[5274]: AH00557: httpd: apr_sockaddr_info_ge...er
Dec 24 10:31:31 Server httpd[5274]: AH00558: httpd: Could not reliably d...ge
Dec 24 10:31:41 Server systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@Server conf]# 
  • Access test on client
    • If the graphical interface is not installed, you can use the command curl 192.168 43.128
    • If a graphical interface is installed, it can be accessed directly through the IP address of the server
[root@Server conf]# curl 192.168.43.128
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<title>Test Page for the Apache HTTP Server on Red Hat Enterprise Linux</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<style type="text/css">
			/*<![CDATA[*/

....

			<div class="content-columns">
				<div class="content-column-left">
					<h2>If you are a member of the general public:</h2>

					<p>The fact that you are seeing this page indicates that the website you just visited is either experiencing problems, or is undergoing routine maintenance.</p>

					<p>If you would like to let the administrators of this website know that you've seen this page instead of the page you expected, you should send them e-mail. In general, mail sent to the name "webmaster" and directed to the website's domain should reach the appropriate person.</p>

					<p>For example, if you experienced problems while visiting www.example.com, you should send e-mail to "webmaster@example.com".</p>

					<p>For information on Red Hat Enterprise Linux, please visit the <a href="http://www.redhat.com/">Red Hat, Inc. website</a>. The documentation for Red Hat Enterprise Linux is <a href="http://www.redhat.com/docs/manuals/enterprise/">available on the Red Hat, Inc. website</a>.</p>
					<hr />
				</div>

				<div class="content-column-right">
					<h2>If you are the website administrator:</h2>

					<p>You may now add content to the directory <tt>/var/www/html/</tt>. Note that until you do so, people visiting your website will see this page, and not your content. To prevent this page from ever being used, follow the instructions in the file <tt>/etc/httpd/conf.d/welcome.conf</tt>.</p>

                                        <p>You are free to use the image below on web sites powered by the Apache HTTP Server:</p>
					
                                        <p align="center"><a href="http://httpd.apache.org/"><img src="/icons/apache_pb2.gif" alt="[ Powered by Apache ]"/></a></p>

				</div>
			</div>
		</div>
	</body>
</html>

  • If you can see the above interface (the default interface), it means that the HTTP service has been successfully installed. Next, you need to modify the configuration file

Modify profile

  • Modify page header file path
[root@Server ~]# cd /etc/httpd/conf/
[root@Server conf]# mv httpd.conf httpd.conf.bak / / back up the configuration file
[root@Server conf]# cat httpd.conf.bak | grep -v "#" | grep -v "^$" > httpd.conf
[root@Server conf]# vim httpd.conf
ServerRoot "/etc/httpd"

Listen 80  //HTTP service port

Include conf.modules.d/*.conf

User apache
Group apache


ServerAdmin root@localhost


<Directory />
    AllowOverride none
    Require all denied
    
#DocumentRoot "/var/www/html"
DocumentRoot "/var/www/Bad"  //Page header file location

...

[root@Server conf]# cd /var/www
[root@Server www]# mkdir Bad
  • Run virtual host configuration
[root@Server www]# rpm -ql httpd | grep vhosts / / view the virtual machine package
/usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
[root@Server www]# cp /usr/share//doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/conf
[root@Server www]# cd /etc/httpd/conf
[root@Server conf]# ls
httpd.conf  httpd.conf.bak  httpd-vhosts.conf  magic
[root@Server conf]# mv httpd-vhosts.conf httpd-vhosts.conf.bak
[root@Server conf]# cat httpd-vhosts.conf.bak | grep -v "#" > httpd-vhosts.conf
[root@Server conf]# vim httpd-vhosts.conf
[root@Server conf]# vim httpd-vhosts.conf
#<VirtualHost *:@@Port@@>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot "@@ServerRoot@@/docs/dummy-host.example.com"
#    ServerName dummy-host.example.com
#    ServerAlias www.dummy-host.example.com
#    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"
#    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common
#</VirtualHost>

<VirtualHost www.bad.boy.com>      //Configure the virtual domain name or access port
    DocumentRoot /var/www/Bad      //Directory of web page header files
    ServerName www.bad.boy.com     //Domain name address
</VirtualHost>
[root@Server conf]#
  • Upload the web page file to the / var/www/Bad directory of the server through Xftp or other remote software
  • Restart the HTTP service
[root@Server ~]# systemctl restart httpd
[root@Server ~]# systemctl status httpd
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since Fri 2021-12-24 12:21:50 CST; 29s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 8406 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
 Main PID: 8410 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─8410 /usr/sbin/httpd -DFOREGROUND
           ├─8411 /usr/sbin/httpd -DFOREGROUND
           ├─8412 /usr/sbin/httpd -DFOREGROUND
           ├─8413 /usr/sbin/httpd -DFOREGROUND
           ├─8414 /usr/sbin/httpd -DFOREGROUND
           └─8415 /usr/sbin/httpd -DFOREGROUND

Dec 24 12:21:30 Server systemd[1]: Starting The Apache HTTP Server...
Dec 24 12:21:40 Server httpd[8410]: AH00557: httpd: apr_sockaddr_info_ge...er
Dec 24 12:21:40 Server httpd[8410]: AH00558: httpd: Could not reliably d...ge
Dec 24 12:21:50 Server systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@Server ~]#

Client test

Linux client testing

  • Use IP address for access test
  • Use domain name for access test
  • The prompt of inaccessibility will appear because the client cannot resolve www.bad boy. COM, because it hasn't been built yet [DNS server] To resolve the domain name, you need to do a local mapping to map the domain name to the IP address of the server
  • Linux client configuration local mapping
[root@Client ~]# vim /etc/hosts
[root@Client ~]# tail -1 /etc/hosts
192.168.43.128 www.bad.boy.com
[root@Client ~]#
  • Reuse the domain name for access testing on Linux clients

Windows client test

  • Use IP for access testing
  • If you directly use the domain name to access, there will also be inaccessible errors
  • In the Windows client, you also need to modify the mapping relationship between IP and domain name to access the domain name normally
    • In the C:\Windows\System32\drivers\etc directory of the host, move the hosts to the desktop, modify it, and add 192.168 43.128 www.bad. boy. Com save
  • Reuse the domain name for access testing on Windows clients
  • After the basic HTTP configuration is completed, you can also modify the HTTP access port, which can be accessed using IP / domain name + port number. For other detailed configurations, please refer to the help manual.
The above contents are original. Please point out any unknown or error.
Author: Bad bad
Link to this article: https://blog.csdn.net/qq_45668124/article/details/122125588
Copyright notice: all articles on this blog are in English unless otherwise stated CC BY-NC-SA 4.0 License agreement. For reprint, please contact the author, indicate the source and attach a link to this article!

Topics: Linux server http