8. Apache Service Lab Note

Source: Internet
Author: User
Tags aliases hosting

Apache Server

A Brief introduction

1 www:world Wide Web www

HTTP protocol: Hypertext Transfer Protocol

HTML language: Hypertext Identity language

2 URL: Unified Resource Locator protocol + domain name: Port + page file name

Http://www.sina.com.cn:80/11/index.html

3 How to build a WWW server

Windows Iis+asp+sqlserver

Internet Information Server

Linux apache+mysql+php

Two-Installation

1. Lamp Source Installation

Production environment security and stability error prompt closed source package , high technical requirements, complex

Lab environment (Replication production environment error prompt on)

Development environment Source Package binary Package

2, RPM package installation Yum Installation

httpd

Mysql

Mysql-server

Php

Php-devel

Php-mysql

Three related documents

Apache configuration file

SOURCE Package Installation:/usr/lcoal/apache2/etc/httpd.conf

/usr/local/apache2/etc/extra/*.conf

RPM Package Installation:/etc/httpd/conf/httpd.conf

Default page Save location:

Web site root directory:/usr/local/apache2/htdocs/

RPM Package Installation:/var/www/html/

Log Save location

Website log:/usr/local/apache2/logs/

RPM Package:/var/log/httpd/

RPM Package Default use log handler/var the source package needs to be set

Log processing:

#tail-F access_log Dynamic View file

1st log cut Apache self-contained log with logs cut

2nd log wheel for Linux self-included logs management logrotate.conf join

#vim/etc/logrotate.conf

/usr/local/apache2/logs/access_log{

Daily

Rotate 30

}

#logrotate-F/etc/logrotate.conf manual operation
#cd/usr/local/apache2/logs/
#ls

Log rotation for all logs

Four configuration files

Vi/root/.bashrc

Alias Sta= '/usr/local/apache2/bin/apachectl start '

Alias sto= '/usr/local/apache2/bin/apachectl stop '

Source/root/.bashrc

#sto
#sta

Note: Apache profiles are strictly case sensitive

1 basic configuration for the host environment

ServerRoot Apache Home Directory

Listen Listening Port

LoadModule Loading of related modules

User

Group Users and Groups

ServerAdmin Admin Mailbox

ServerName server name (without domain name resolution, use temporary parsing.) Do not open)

Errorlog "Logs/error_log error log

Customlog "Logs/access_log" common correct access log

DirectoryIndex index.html index.php Default page name, priority order

Include etc/extra/httpd-vhosts.conf the contents of the child profile are also loaded into effect

2 Home directories and permissions

DocumentRoot "/usr/local/apache2//htdocs"

Home Directory

<directory "/usr/local/apache2//htdocs" >

#Directory关键字定义目录权限

Options Indexes FollowSymLinks

#options

None: No additional permissions

All: All Permissions

Indexes: Browse permissions (display directory contents when there is no default Web page file in this directory)

FollowSymLinks: Allow soft connections to other directories

AllowOverride None

#定义是否允许目录下 permissions in the. htaccess file take effect

Permissions in None:.htaccess do not take effect

All: All permissions in the file are in effect

Authconfig: In the file, only Web authentication permissions are in effect.

Require all granted Access control List 403 Error 404 error

#定义此目录的允许访问权限

Example 1: Allow only host access with IP 192.168.1.1

Require all denied

Require IP 192.168.1.1

Example 2. Allow only host access to the 192.168.1.0/24 network

Require all denied

Require IP 192.168.1.0/24

Example 3. Prohibit 192.168.1.2 host access, others are allowed to access,

<RequireAll>

Require all granted

Require not IP 192.168.1.2

</RequireAll>

Example 4. Allow all Access,

Require all granted

Example 5. Deny all Access,

Require all denied

3 Directory alias purpose extending the Site directory, adding servers, using two-level domain names, using directory aliases

Child Profile Name etc/extra/httpd-autoindex.conf

alias/icons/"/usr/local/apache2//icons/"

Apache thought here the actual directory location

Define alias/icons/----

http://192.168.1.253/icons/

<directory "/usr/local/apache2//icons" >

Options Indexes MultiViews

AllowOverride None

Require all granted

</Directory>

Modifying a child configuration file
#vim/usr/local/apache2/extra/httpd-autoindex.conf
alias/www/"/usr/local/apache2/www/"
<directory "/usr/local/apache2/www/" >
Options Indexes
AllowOverride None
Require all granted
</Directory>

3) Create/usr/local/apache2/www directory
#mkdir/usr/local/apache2/www

4) Restart Service test
#sto
#sta

Test 192.168.172.251/www/

4 user authentication

Restricts specific directories that are accessible only to specified users.

1) Create a directory to protect

Use aliases to create a directory at the system location, and then protect

Mkdir-p/share/soft

2) Modify the configuration file to allow permission files to take effect

Vi/usr/local/apache2/etc/httpd.conf

453 Include etc//extra/httpd-autoindex.conf

#vim/usr/local/apache2/etc/extra/httpd-autoindex.conf
PNS alias/soft/"/share/soft/"
<directory "/share/soft/" >
The Indexes Options
AllowOverride All
Require all granted
</Directory>

alias/soft/"/share/soft/"

<directory "/share/soft" >

Options Indexes

AllowOverride all #开启权限认证文件. htaccess

Require all granted

</Directory>

Restart Apache

3) Create a permission file in the specified directory

Establish/share/soft/.htaccess Permissions File
#vim/share/soft/.htaccess
1 AuthName "172PHP"
2 AuthType Basic
3 authuserfile/share/apache.passwd
4 Require Valid-user

Cd/share/soft

Vi. htaccess #不区分大小写

AuthName "Docs"

#提示信息

AuthType Basic

#加密类型

authuserfile/share/apache.passwd

#密码文件, the file name is customized.

Require Valid-user

#允许密码文件中所有用户访问

4) Create a password file and join the user who is allowed to access it. User and System User Independent

/usr/local/apache2/bin/htpasswd-c/share/apache.passwd Test1

-C Create a password file, only the first user can be added to the-c

/usr/local/apache2/bin/htpasswd-m/share/apache.passwd Test2

-M and add more users

Restart Service test
#sto
#sta

Test 192.168.172.251/soft/

5 Virtual Hosting

1) Classification

IP-based virtual host: one server, multiple IPs, multiple sites built

Port-based virtual host: one server, one IP, multiple sites, each with a different port access

Name-based virtual hosting: one server, one IP, multiple Web sites, each with a different domain access

2) Steps:

① Analytical Test Domain name

192.168.172.251 www.sina.com
192.168.172.251 www.sohu.com

C:\WINDOWS\system32\drivers\etc\hosts WINDOWS

/etc/hosts Linux

② Planning website Home Directory

#mkdir/share/sina/
#mkdir/share/sohu/
#vim/share/sina/index.html
#vim/share/sohu/index.html

/share/sina--------------www.sina.com

/share/sohu------------www.sohu.com

③ Modifying a configuration file

Vi/usr/local/apache2/etc/httpd.conf

465 Include etc//extra/httpd-vhosts.conf

#打开虚拟主机配置文件

Vi/usr/local/apache2/etc/extra/httpd-vhosts.conf

<directory "/usr/local/apache2/htdocs/sina" >

Options Indexes

AllowOverride None

Require all granted

</Directory>

<directory "/usr/local/apache2/htdocs/sohu" >

Options Indexes

AllowOverride None

Require all granted

</Directory>

<directory "/share/sina" >
Options Indexes
AllowOverride None
Require all granted
</Directory>
28
<directory "/share/sohu" >
Options Indexes
AllowOverride None
Require all granted
</Directory>

<virtualhost 192.168.150.253>

#注意, can only write IP

ServerAdmin [email protected]

#管理员邮箱

DocumentRoot "/usr/local/apache2/htdocs/sina"

#网站主目录

ServerName www.sina.com

#完整域名

Errorlog "Logs/sina-error_log"

#错误日志

Customlog "Logs/sina-access_log" common

#访问日志

</VirtualHost>

<virtualhost 192.168.150.253>

ServerAdmin [email protected]

DocumentRoot "/usr/local/apache2/htdocs/sohu"

ServerName www.sohu.com

Errorlog "Logs/sohu.com-error_log"

Customlog "Logs/sohu.com-access_log" common

</VirtualHost>

<virtualhost 192.168.172.251>
ServerAdmin [email protected]
PNS documentroot "/share/sina/"
ServerName www.sina.com
errorlog "Logs/sina-error_log"
customlog "Logs/sina-access_log" Common
</VirtualHost>
the
<virtualhost 192.168.172.251>
ServerAdmin [email protected]
documentroot "/share/sohu/"
ServerName www.sohu.com
errorlog "Logs/sohu-error_log"
customlog "Logs/sohu-access_log" Common
</VirtualHost>

Restart Service test
#sto
#sta

Test www.sina.com www.sohu.com

6 rewrite rewrite feature URL

Enter an address in the URL and automatically jump to another

1) domain name jump www.sina.com------> www.sohu.com

Turn on the virtual host and access it normally

# vi/usr/local/apache2/etc/httpd.conf

147LoadModule Rewrite_module modules/mod_rewrite.so

#打开重写模块, remember to restart Apache.

Modify the configuration file to make the. htaccess file of the Sina directory effective

# VI Extra/httpd-vhosts.conf

<directory "/usr/local/apache2/htdocs/sina" >

Options Indexes FollowSymLinks

AllowOverride All

Require all granted

</Directory>

#vim/usr/local/apache2/etc/extra/httpd-vhosts.conf
<directory "/share/sina" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Vi/usr/local/apache2/htdocs/sina/.htaccess

Establish/share/sina/.htaccess
#vim/share/sina/.htaccess

Rewriteengine on

#开启rewrite功能

Rewritecond%{http_host} www.sina.com

Assigns the content beginning with www.sina.com to the http_host variable

Rewriterule. * http://www.sohu.com

. * Enter any address, jump to http://www.sohu.com

1 Rewriteengine on
2 Rewritecond%{http_host} www.sina.com
3 rewriterule. * http://www.sohu.com

Restart Service test
#sto
#sta

Test Www.sina.com-Www.sohu.com

2) page file Jump

Vi/usr/local/apache2/htdocs/sina/.htaccess

Rewriteengine on

Rewriterule index (\d+). HTML index.php?id=$1

# Enter an index (value). When you html, jump to the index.php file and pass the value as a variable into the index.php

#vim/share/sina/.htaccess
1 Rewriteengine on
2 Rewriterule Index (\d+). HTML index.php?id=$1

#cd/share/sina
#vim index.php
<?php
echo "Yemian rewrite";
?>

Test www.sina.com/index5.html

7 Common child Profiles

httpd-autoindex.conf Apache System aliases

httpd-default.conf Thread Control *

Httpd-info.conf Status Statistics Page

Httpd-languages.conf Language code *

httpd-manual.conf Apache Help documentation

httpd-mpm.conf Maximum number of connections *

httpd-multilang-errordoc.conf wrong page *

HTTPD-SSL.CONF SSL Secure Socket Access

httpd-userdir.conf User Home Directory Configuration

Httpd-vhosts.conf Virtual Host

8. Apache Service Lab Note

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.