Linux Beginner-apache articleApache provides Hypertext Transfer Protocol HTTP,HTTPD is the primary server for Apache Hypertext Transfer Protocol. A brief description of the installation and configuration of the httpd is provided below.
1. Installation
"Yum install Httpd-y". Install the HTTPD service.
"Systemctl start httpd", "Systemctl Enable httpd", "Systemctl stop Firewalld". Configure the HTTPD service.
2. Default Publishing page
The default publishing page for the httpd service is "/var/www/html/index.html", which does not exist at the beginning of the file. For example, the "index.html" under the directory "/var/www/html/" writes the content shown. You can see it by entering the IP in the browser.
In the 164th line of the file "/etc/httpd/conf/httpd.conf", you can change the default publishing page, as shown in, and change the default publishing page to "we.html", indicating that if "we.html" does not exist, access "index.html". Restart the service when you are finished.
"Vim/var/www/html/we.html". Edit the contents in the file and enter the IP in the browser.
3. Default Publishing Directory
The default publishing directory for the HTTPD service is "/var/www/html". If you want to change this default publishing directory, you need to configure the following:
A, "mkdir/xue/html-p". Create a directory as the default publishing directory.
B, "vim/etc/httpd/conf/httpd.conf". Edit the following in the configuration file, as shown in lines 120th through 123th:
DocumentRoot "/xue/html"
<directory "/xue/html" >
Require all granted
</Directory>
C, "Semanage fcontext-a-T httpd_sys_content_t '/xue (/.*)?". Modify the security context of the "/xue" directory and refresh it with "Restorecon-rvvf/xue".
D, "vim/xue/html/we.html". Write the contents in the file "we.html".
After the configuration is complete, restart the service, enter the IP in the browser, you can see the contents of the edited file in D.
4. Access by password
The HTTPD service can also be set by entering a password to see the contents of the page. Its configuration is as follows:
A, "cd/etc/httpd/conf/". Enter this directory.
B, "htpasswd-cm username admin". Add a user admin and enter the password two times. A file "username" is automatically generated when the add is complete. If you continue to add users, you need to change the parameter "-cm" to "-M". If the parameter "-C" is added, the original user is overwritten.
C, "vim/etc/httpd/conf/httpd.conf". Enter the following in the configuration file, as shown in lines 121th to 127th:
<directory "/xue/html" >
# Require All granted
Authuserfile/etc/httpd/conf/username
AuthName "Please input your username and password"
AuthType Basic
Require Valid-user
</Directory>
Restart the service after completion, re-access from the browser, you need to enter a password, verify before you can see the page inside.
In the above settings, you can also change "Require Valid-user" in C to "Require user". So that only the specified user can log on successfully.
5. Access Management
By editing the profile "etc/httpd/conf/httpd.conf", you can set a ban or allow some users to access it. The configuration method is shown in lines 128th through 130th. Takes effect after restarting the service. "Order Allow,deny" means to turn on the Allow or disallow access feature, and which of the previous gentlemen is valid, here "Allow" takes effect first. "Allow from all" means that all users are allowed access. "Deny from 172.25.254.102" means that user access to the IP "172.25.254.102" is forbidden. According to the preceding sequence, users with IP "172.25.254.102" will not be able to access it.
6. Virtual Publishing Directory
HTTPD can also be published from multiple directories, the default publishing directory is the primary publishing directory, and the other directories are virtual publishing directories. For example, the transition between pages on a Web page is the virtual publishing directory used, rather than using multiple servers.
The configuration of the virtual publishing directory is as follows:
A, "mkdir/etc/www/126/game.126.com/etc/www/126/music.126.com-p". Build two virtual publishing directories "game.126.com" and "music.126.com".
B, "vim/etc/www/126/game.126.com/index.com". Edit the Publish page for "game.126.com" as shown in.
C, "vim/etc/www/126/music.126.com/index.com". Edit the Publish page for "music.126.com" as shown in.
D, "CD/ETC/HTTPD/CONF.D". Enter this directory.
C, "Vim default.conf". Edit the default publishing page and edit the following as shown in:
<virtualhost _default_:80>
DocumentRoot "/var/www/html"
Customlog "Logs/deault.log" combined
</Virtualhost>
D, "Vim game.conf". Edit the file "Game.126.com". Edit the following as shown in:
<virtualhost *:80>
Servername game.126.com
Documentroot/var/www/126/game.126.com
Customlog "Logs/game.log" combined
</Virtualhost>
<directory "/var/www/126/game.126.com" >
Require all granted
</Directory>
E, "Vim music.conf". Edit the file "Music.126.com". The content is the same as "game.conf", replacing the "game" with "music".
After restarting the service, the Virtual publishing page is configured to complete. When testing, enter "Vim/etc/hosts" on the other host to configure local resolution, edit "172.25.254.202 www.126.com game.126.com music.126.com".
You can see different pages by entering "www.126.com", "game.126.com", and "music.126.com" in the browser on the test host.
7, HTTPS
HTTPS is a secure version of HTTP, often used for password landing and other pages, to achieve the encryption between the client and server data transmission. The configuration steps for HTTPS are as follows:
A, "Yum install Mod_ssl.x86_64-y". Download the cryptographic module SSL.
B, "Netstat-antlpe | grep http ". See if port 443 is on and port 443 is HTTPS.
C, "Yum install Crypto-utils.x86_64-y". Install the certificate and key generator software.
D, "Genkey www.126.com". Generate a certificate and key for "www.126.com". It is generated as a graphical interface, as shown in the steps.
Enter the interface, prompt for the certificate and key storage location, click Next.
Enter the Select encryption length interface. Select and then click Next.
Go to the File Check screen.
After the completion of the key generation interface, you need to enter something on the server, or shake the number of labels.
After completion, enter the following interface, click No, because yes is required money, is the official certification, if the enterprise needs, then click Yes.
When you are finished, go to the following screen and click Next directly.
After completion, enter the following interface, enter the information of the certification certificate. Click Next when you are done.
E, "vim/etc/httpd/conf.d/ssl.conf". Edit the configuration file, as follows, enter the generated certificate and the file location where the key is located. Lines 100th and 107th are as follows:
Sslcertificatefile/etc/pki/tls/certs/www.126.com.crt
Sslcertificatekeyfile/etc/pki/tls/private/www.126.com.key
The configuration of the encrypted page is complete and takes effect after restarting the service. Entering "https://172.25.254.202" in the browser requires authentication before it can be seen.
View the certificate, as you entered when you set up the certificate.
When the above configuration is completed, you need to enter "https" when accessing the webpage, obviously this is unreasonable, need to go to the HTTPS page directly when accessing the domain name. The following configuration is also required:
A, "mkdir/var/www/126/login.126.com". Create a virtual publishing directory.
B, "vim/var/www/126/login.126.com/index.html". Configure the Virtual publishing page, as shown in.
C, "vim/etc/httpd/conf.d/login.conf". Configures a file for a virtual publishing page. The contents are as follows:
<virtualhost *:443>
Servername login.126.com
Documentroot/var/www/126/login.126.com
Customlog "Logs/music.log" combined
Sslengine on
Sslcertificatefile/etc/pki/tls/certs/www.126.com.crt
Sslcertificatekeyfile/etc/pki/tls/private/www.126.com.key
</VirtualHost>
<directory "/var/www/126/login.126.com" >
Require all granted
</Directory>
<virtualhost *:80>
ServerName login.126.com
Rewriteengine on
Rewriterule ^ (/.*) $ https://%{http_host}$1 [redirect=301]
</VirtualHost>
where "*:443" means to change the port to 443. "Sslengine on" means encryption on, followed by the location of the certificate and key. "Rewriteengine on" means that the override function is turned on. "Rewriterule ^ (/.*) $ https://%{http_host}$1 [redirect=301]" represents the rewrite rule, "^ (/.*) $" is the character entered on the client, "%{http_host}" represents the client request host, "$" The representation here represents "^ (/.*) $", "redirect=301", which indicates that the redirection level is temporary redirect, if 302 indicates permanent redirection.
When testing, add "login.126.com" to the "/etc/hosts" local parsing file in the client host and enter the "login.126.com" test.
As you can see, the webpage automatically jumps to "https://login.126.com", obtains the authentication certificate, can see the page content.
Linux Beginner-apache article