One of the CentOS 7.4--apache applications to build a Web virtual directory

Source: Internet
Author: User

Directory
The first part of the preparatory work
Second part installs Apache service
The third part constructs the virtual directory (open access and authorized authentication Access)

The first part of the preparatory work
One: server: Linux system-centos 7.4;
IP Address: 192.168.80.10

Client: Take WIN7 as an example, test the result of verification, and the server in the same network segment;
IP Address: 192.168.80.2

Two: Download the compressed package
http://httpd.apache.org/download.cgi//http Compression Pack
http://apr.apache.org/download.cgi//http Plug-in package

Apr-1.6.2.tar.gz and apr-util-1.6.0.tar.gz are required plugins for httpd2.4 later versions and must be installed

Third: Close the firewall with SELinux

Second part installs Apache service
One: Install the compilation tools and plugins
[[email protected] ~]# yum-y install \

GCC \
gcc-c++ \
Make \
Pcre-devel \
Expat-devel \
Perl

Two: Unzip:
[Email protected] ~]# Tar XF apr-1.6.2.tar.gz
[Email protected] ~]# Tar XF apr-util-1.6.0.tar.gz
[Email protected] ~]# Tar XF httpd-2.4.29.tar.bz2

Put the plug-in into the httpd directory
[Email protected] ~]# MV apr-1.6.2 HTTPD-2.4.29/SRCLIB/APR
[Email protected] ~]# MV apr-util-1.6.0 httpd-2.4.29/srclib/apr-util

Three: Configuration (custom personalization)
[[Email protected] ~]# CD httpd-2.4.29//must enter the installation directory
[Email protected] httpd-2.4.29]#/configure \

--PREFIX=/USR/LOCAL/HTTPD \//Specifies to install the HTTPD program into the/USR/LOCAL/HTTPD directory
--ENABLE-SO \//Enable dynamic load module function
--enable-rewrite \//Enable Web page address rewriting for website optimization and Directory Migration
--enable-charset-lite \//enable character set support to support Web pages that are encoded using a variety of character sets
--ENABLE-CGI//Enable CGI scripting support for extended Web site application access

IV: Compilation and Installation
[[email protected] httpd-2.4.29]# make && make install

To add a httpd service to a system service
[Email protected] httpd-2.4.29]# CP/USR/LOCAL/HTTPD/BIN/APACHECTL/ETC/INIT.D/HTTPD
[Email protected] httpd-2.4.29]# VI/ETC/INIT.D/HTTPD
Add the following two lines (Note that "#" cannot be omitted):

Save exit
[[email protected] httpd-2.4.29]# chkconfig--add httpd//Add httpd to service Manager
[[email protected] httpd-2.4.29]# Systemctl daemon-reload//heavy-duty system System Manager

V: Edit httpd master configuration file
[Email protected] httpd-2.4.29]# vi/usr/local/httpd/conf/httpd.conf
Modify the following content:
ServerName www.aa.com
Save exit

Optimized execution path (the original path of the executing program file is not in the PATH environment variable, do a soft link to make it executable)
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/conf/httpd.conf/etc/
[Email protected] httpd-2.4.29]# ln-s/usr/local/httpd/bin/*/usr/local/bin/

Check for syntax errors
[Email protected] httpd-2.4.29]# httpd–t
Or: [[email protected] httpd-2.4.29]# apachectl–t

View Program version

Six: Start the service
[Email protected] httpd-2.4.29]# systemctl start httpd
[[email protected] httpd-2.4.29]# Systemctl enable httpd//set httpd to boot
[Email protected] httpd-2.4.29]# NETSTAT-ANPT | grep 80//View httpd service Run status

Seven: Validation
Accessing the server with the WIN7 client
Browser access: http://192.168.80.10

Validation successful
(Note that the default content of the Web page is:/usr/local/httpd/htdocs/index.html)

The third part builds the Web virtual directory
One: Edit the HTTP master configuration file
[Email protected] ~]# vi/etc/httpd.conf
Include conf/conf.d/*.conf//new line to include child profiles
Save exit

Two: Create a virtual directory configuration file
[[email protected] ~]# cd/usr/local/httpd/conf///Enter HTTPD installation directory
[Email protected] conf]# mkdir CONF.D
[Email protected] conf]# CD CONF.D
[email protected] conf]# Touch vdir.conf

Three: Build a Web virtual directory
Scenario One: Open access, no account password required to access
First step: Edit the configuration file
[Email protected] conf.d]# VI vdir.conf
Add the following content:
alias/doc/"/usr/share/doc/"//define shared aliases (access to Doc directory directly)
<directory "/usr/share/doc" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny//define white list
Allow from all//edit whitelist for everyone to access
Require all granted//open this directory access (allow everyone to access)
</Directory>
Save exit

Step Two: Restart the service
[[email protected] conf.d]# systemctl restart httpd//Restart Service
[Email protected] conf.d]# NETSTAT-ANPT | grep http//view httpd running status

Step Three: Verify
Win7 under Browser access http://192.168.80.10/doc/

Validation successful

Scenario Two: Authorized access, requires account password to access
First step: Edit the configuration file
[Email protected] conf.d]# VI vdir.conf
Add the following content (delete the original content):
Alias/share/"/usr/share/doc/"
<directory "/usr/share/doc/" >
Options Indexes multiviews FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
AuthName "wellcom!!"//Certification Name
AuthType Basic//authentication type
Authuserfile/usr/local/httpd/user//authenticated user files
Require Valid-user
#Require all granted
</Directory>
Save exit

Step Two: Restart the service
[Email protected] conf.d]# systemctl restart httpd
[Email protected] conf.d]# NETSTAT-ANPT | grep httpd

Step three: Create an authenticated user
[[email protected] conf.d]# htpasswd-c/usr/local/httpd/user Test//Add-C Create a user account file and then create users test, enter the password two times
[[email protected] conf.d]# Htpasswd/usr/local/httpd/user Jack//create user jack, enter the password two times
[[email protected] conf.d]# Cat/usr/local/httpd/user//view created user

Fourth Step: Verify
Win7 under Browser access http://192.168.80.10/share/

Enter your account and password to sign in

Validation successful

One of the CentOS 7.4--apache applications to build a Web virtual directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.