Apache Services for Linux

Source: Internet
Author: User

I. Installation of Apache
Yum Install httpd-y installation Service
Systemctl Start httpd Startup service
Systemctl Stop FIREWALLD Firewall off
Systemctl Enable httpd boot automatically
Systemctl Disable FIREWALLD boot does not start the firewall

Two. Apache-related configuration information

Default publish directory file for 1.apache
/var/www/html/index.html

Configuration file for 2.apache
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf

Default port for 3.apache
80

Three. Basic configuration of Apache

1. Modify the default publishing file

(1) vim/etc/httpd/conf/httpd.conf
164 DirectoryIndex westos.html Index.thml

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9E/3F/wKioL1mOXiGjeGM1AAApSoKdMpc333.png "style=" float : none; "title=" screenshot from 2017-08-11 15-05-17.png "alt=" Wkiol1moxigjegm1aaapsokdmpc333.png "/>

Vim Westos

Hello, westos!.

Default first read write in previous publish file, westos.html file corrupted, read index.html file

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9E/50/wKiom1mOXBvCj-6FAAAt-AqmjS8228.png "style=" float : none; "title=" screenshot from 2017-08-11 15-00-29.png "alt=" Wkiom1moxbvcj-6faaat-aqmjs8228.png "/>

Restart Apache Service systemctl Restart HTTPD, visit the main page for westos.html

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9E/3F/wKioL1mOXBuDAnmVAABVy9bR758367.png "style=" float : none; "title=" screenshot from 2017-08-11 15-03-47.png "alt=" Wkiol1moxbudanmvaabvy9br758367.png "/>

(2) Delete Westos publishing page, index becomes the default publish file

Vim Westos

Hello, world!.

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9E/51/wKiom1mOXiHwGCXYAABjb2q_6Q0476.png "style=" float : none; "title=" screenshot from 2017-08-11 15-05-28.png "alt=" Wkiom1moxihwgcxyaabjb2q_6q0476.png "/>

Port Display OK

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9E/3F/wKioL1mOXiKQF37BAABsE_On0zo791.png "style=" float : none; "title=" screenshot from 2017-08-11 15-11-15.png "alt=" Wkiol1moxikqf37baabse_on0zo791.png "/>

Restart the Apache service to access the main page for index.html

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9E/3F/wKioL1mOXiCBOhRKAABQabZ02CM798.png "style=" float : none; "title=" screenshot from 2017-08-11 15-04-30.png "alt=" Wkiol1moxicbohrkaabqabz02cm798.png "/>

2. Modify the default publishing directory

(1) When SELinux is disable state
Vim/etc/httpd/conf/httpd.conf
DocumentRoot "/westos/html" Modify the default publishing directory to/westos/html

<directory "/westos/html" >
Require all granted everyone can access

</Directory>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/3F/wKioL1mOYDiDQXLGAAAY6cxeLDo114.png "style=" float : none; "title=" screenshot from 2017-08-11 15-27-10.png "alt=" Wkiol1moydidqxlgaaay6cxeldo114.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9E/3F/wKioL1mOYDeBcxUnAABLrYEyYUs436.png "style=" float : none; "title=" screenshot from 2017-08-11 15-22-56.png "alt=" Wkiol1moydebcxunaablryeyyus436.png "/>

Systemctl Restart httpd


Create a new publish directory/westos/html

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9E/3F/wKioL1mOYDfzp__BAABEf5EbExQ631.png "style=" float : none; "title=" screenshot from 2017-08-11 15-26-24.png "alt=" Wkiol1moydfzp__baabef5ebexq631.png "/>

Writing Westos Publishing files

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/51/wKiom1mOYDjR0Ip7AAAkJGScTwQ197.png "style=" float : none; "title=" screenshot from 2017-08-11 15-27-01.png "alt=" Wkiom1moydjr0ip7aaakjgsctwq197.png "/>

Restart the service to access the files under the new directory OK

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9E/3F/wKioL1mOYDnxdfDOAABdo--ZWUA572.png "style=" float : none; "title=" screenshot from 2017-08-11 15-28-07.png "alt=" Wkiol1moydnxdfdoaabdo--zwua572.png "/>


(2) When SELinux is enforcing state
Vim/etc/httpd/conf/httpd.conf
DocumentRoot "/westos/html" Modify the default publishing directory to/westos/html

<directory "/westos/html" >
Require all granted everyone can access
</Directory>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/3F/wKioL1mOYDiDQXLGAAAY6cxeLDo114.png "style=" float : none; "title=" screenshot from 2017-08-11 15-27-10.png "alt=" Wkiol1moydidqxlgaaay6cxeldo114.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9E/3F/wKioL1mOYDeBcxUnAABLrYEyYUs436.png "style=" float : none; "title=" screenshot from 2017-08-11 15-22-56.png "alt=" Wkiol1moydebcxunaablryeyyus436.png "/>

Systemctl Restart httpd


Create a new publish directory/westos/html

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9E/3F/wKioL1mOYDfzp__BAABEf5EbExQ631.png "style=" float : none; "title=" screenshot from 2017-08-11 15-26-24.png "alt=" Wkiol1moydfzp__baabef5ebexq631.png "/>

Writing Westos Publishing files

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/51/wKiom1mOYDjR0Ip7AAAkJGScTwQ197.png "style=" float : none; "title=" screenshot from 2017-08-11 15-27-01.png "alt=" Wkiom1moydjr0ip7aaakjgsctwq197.png "/>


To view the default publishing directory and the context of the new directory, set the context for the new directory Westos to httpd_sys_content_t

After the modification is complete, update the context Restorecon-rvvf/westos

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/51/wKiom1mOYDmTbPvgAAFXRazZVsg442.png "style=" float : none; "title=" screenshot from 2017-08-11 15-27-46.png "alt=" Wkiom1moydmtbpvgaafxrazzvsg442.png "/>

Restart the service to access the files under the new directory OK

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9E/3F/wKioL1mOYDnxdfDOAABdo--ZWUA572.png "style=" float : none; "title=" screenshot from 2017-08-11 15-28-07.png "alt=" Wkiol1moydnxdfdoaabdo--zwua572.png "/>

3.apache of access control
(1) Setting IP access(where order is executed sequentially)
Vim/etc/httpd/conf/httpd.conf
<directory "/westos/html" > Allow everyone to access Westos directory but deny 250 hosts
Order Allow,deny
Allow from all
Deny from 172.25.254.250
</Directory>

<directory "/westos/html" > Allow only 250 hosts to access Westos directory
Order Deny,allow
Allow from 172.25.254.250
Deny from all
</Directory>


(2) Setting user's access
Htpasswd-m/etc/httpd/accessuser Admin Create Access user authentication file (-c create-m Specify name)

Note: The first user created needs to add C, the user created later does not need to add C, directly specify-m


Create Access user admin Admin1 Specify name Authfile

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9E/40/wKioL1mOaADxVdAbAAByj8pN0zY509.png "style=" float : none; "title=" screenshot from 2017-08-11 16-14-14.png "alt=" Wkiol1moaadxvdabaabyj8pn0zy509.png "/>


Configuring the Authentication Configuration

Vim/etc/httpd/conf/httpd.conf
<directory "/westos/html" >
Authuserfile/etc/httpd/conf/authfile User Authentication File
AuthName "Please input your name and password!" User authentication Prompt Information
AuthType Basic Certification Type BASIC Certification
Require Valid-user authenticated user, all users in the authentication file can pass
Require user admin only allows admin users in the authentication file to access
</Directory>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/40/wKioL1mOaqHC7xa1AACQ_8egKXw123.png "title=" Screenshot from 2017-08-12 10-40-04.png "alt=" Wkiol1moaqhc7xa1aacq_8egkxw123.png "/>


Put the authentication file on the/etc/httpd/conf and restart the service

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9E/51/wKiom1mOaAHROwhbAAAtuwpvM9E287.png "style=" float : none; "title=" screenshot from 2017-08-11 16-17-14.png "alt=" Wkiom1moaahrowhbaaatuwpvm9e287.png "/>


Visit 172.25.254.128 again, need to enter the authentication account number and password

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9E/40/wKioL1mOaALRL-NxAAD-MLpedqk507.png "style=" float : none; "title=" screenshot from 2017-08-11 16-17-40.png "alt=" Wkiol1moaalrl-nxaad-mlpedqk507.png "/>

Enter your account password and go to the access page

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9E/51/wKiom1mOaAOBO8Y2AAA6eK1q1Ow814.png "style=" float : none; "title=" screenshot from 2017-08-11 16-17-59.png "alt=" Wkiom1moaaobo8y2aaa6ek1q1ow814.png "/>



Four. Apache Virtual host

1. Definition
Allows one of our Apache servers to display different home pages when accessing different domain names

2. Create a test page

Create a catalog test publish file and change the default directory to/var/www/html/

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9E/40/wKioL1mObPXRWLgSAAC7eEls154751.png "style=" float : none; "title=" screenshot from 2017-08-11 16-44-03.png "alt=" Wkiol1mobpxrwlgsaac7eels154751.png "/>


Creating News.westos.com and Sport.westos.com directories

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9E/52/wKiom1mObPfQCsIaAACSfjsPWz0780.png "style=" float : none; "title=" screenshot from 2017-08-11 16-48-42.png "alt=" Wkiom1mobpfqcsiaaacsfjspwz0780.png "/>


Create a publishing file under News

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9E/52/wKiom1mObPax4A1JAAAiyAHWh2w595.png "style=" float : none; "title=" screenshot from 2017-08-11 16-47-30.png "alt=" Wkiom1mobpax4a1jaaaiyahwh2w595.png "/>


Create a publish file under Sports

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9E/40/wKioL1mObPaCgLVeAAArUif9z6w269.png "style=" float : none; "title=" screenshot from 2017-08-11 16-48-34.png "alt=" Wkiol1mobpacglveaaaruif9z6w269.png "/>


3. Configuration

CD to/etc/httpd/conf.d/


(1) Create an Access profile for a new domain name that is not specified

vim/etc/httpd/conf.d/default.conf access to the default domain name is not specified
<virtualhost _default_:80> Virtual Host open port
DocumentRoot Default Publishing directory for "/var/www/html" virtual hosts
Customlog "Logs/default.log" Combined virtual host log
</Virtualhost>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9E/40/wKioL1mObPeQweweAAA2pwigz8g476.png "style=" float : none; "title=" screenshot from 2017-08-11 16-54-04.png "alt=" Wkiol1mobpeqweweaaa2pwigz8g476.png "/>

(2) New Access file for news.westos.com domain name

Vim/etc/httpd/conf.d/news.conf the specified domain name news.westos.com access to the specified default publishing directory
<virtualhost *:80>
ServerName news.westos.com
Documentroot/var/www/westos/news.westos.com
Customlog "Logs/news.log" combined
</Virtualhost>
<directory "/var/www/westos/news.westos.com" > Access authorization for the default publishing directory
Require all granted
</Directory>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9E/40/wKioL1mObPiBaiT_AACuYYbBFuY494.png "style=" float : none; "title=" screenshot from 2017-08-11 17-01-49.png "alt=" Wkiol1mobpibait_aacuyybbfuy494.png "/>

(3) New Access file for sports.westos.com domain name

Vim/etc/httpd/conf.d/sports.conf the specified domain name sports.westos.com access to the specified default publishing directory
<virtualhost *:80>
ServerName sports.westos.com
Documentroot/var/www/westos/sports.westos.com
Customlog "Logs/sports.log" combined
</Virtualhost>
<directory "/var/www/westos/sports.westos.com" > Access authorization for the default publishing directory
Require all granted
</Directory>

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9E/40/wKioL1mObPjjQ1TQAAC0PlpGNsw654.png "style=" float : none; "title=" screenshot from 2017-08-11 17-02-30.png "alt=" Wkiol1mobpjjq1tqaac0plpgnsw654.png "/>

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9E/52/wKiom1mObPnRP308AABcnH5U9Lg583.png "style=" float : none; "title=" screenshot from 2017-08-11 17-05-47.png "alt=" Wkiom1mobpnrp308aabcnh5u9lg583.png "/>


4. Testing
Test on the 172.25.254.28

Configure local parsing files in the host where the browser resides vim/etc/hosts
172.25.254.128 www.westos.com news.westos.com sports.westos.com

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9E/41/wKioL1mOc42hKTM9AABFhC-N_sY495.png "style=" float : none; "title=" screenshot from 2017-08-11 17-13-58.png "alt=" Wkiol1moc42hktm9aabfhc-n_sy495.png "/>


Open www.westos.com in the browser, access to the default file

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9E/41/wKioL1mOc4yziVNWAAAx0sGDGAM340.png "style=" float : none; "title=" screenshot from 2017-08-11 17-11-35.png "alt=" Wkiol1moc4yzivnwaaax0sgdgam340.png "/>

Open news.westos.com in the browser, access to the news file

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9E/52/wKiom1mOc42gh9b_AAAz8dneDTM522.png "style=" float : none; "title=" screenshot from 2017-08-11 17-11-46.png "alt=" Wkiom1moc42gh9b_aaaz8dnedtm522.png "/>

In the browser open sports.westos.com, access to the sports file

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9E/52/wKiom1mOc47BR7HbAAA4H33tvqM070.png "style=" float : none; "title=" screenshot from 2017-08-11 17-14-19.png "alt=" Wkiom1moc47br7hbaaa4h33tvqm070.png "/>




Apache Services for Linux

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.