Linux (eight) Apache server

Source: Internet
Author: User
Tags aliases hosting

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, high technical requirements, complex
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:
SOURCE Bundle:/usr/local/apache2/htdocs/
RPM Package Installation:/var/www/html/

Log Save location
SOURCE Bundle:/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:
1st log cut Apache self-contained log with logs cut
2nd log wheel for Linux self-bring logs management logrorate.conf
Join/usr/local/apache2/logs/access_log{
Daily
Rotate 30
}
Logrotate-f/etc/logrotate.conf

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

Note: Apache profiles are strictly case sensitive

1 basic configuration for the host environment

Serverrootapache 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 host access to 192.168.1.0/24 networks only
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>

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
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
Cd/share/soft

Vi. htaccess# Case insensitive
AuthName "Docs" #提示信息
AuthType Basic #加密类型
AUTHUSERFILE/SHARE/APACHE.PASSWD #密码文件, file name customization.
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

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
Www.sina.com
Www.sohu.com
C:\WINDOWS\system32\drivers\etc\hosts WINDOWS
/etc/hosts Linux


② Planning website Home Directory
/share/sina--------------www.sina.com
/share/sohu------------www.sohu.com

③ Modifying a configuration file
Vi/usr/local/apache2/etc/httpd.conf
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>

<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>

6rewrite 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

[Email protected] ~]# vi/usr/local/apache2/etc/httpd.conf
LoadModule Rewrite_module modules/mod_rewrite.so
#打开重写模块, remember to restart Apache.

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

[Email protected] etc]# VI extra/httpd-vhosts.conf

<directory "/usr/local/apache2/htdocs/sina" >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Vi/usr/local/apache2/htdocs/sina/.htaccess
Rewriteengine on #开启rewrite功能
Rewritecond%{http_host} www.sina.com #把以www. Sina.com the beginning of the content assignment to the http_host variable
Rewriterule. * http://www.sohu.com #.* Enter any address, jump to http://www.sohu.com

2) page File jump
Vi/usr/local/apache2/htdocs/sina/.htaccess
Rewriteengine on
Rewriterule index (\d+). HTML index.php?id=$1
#输入index (numeric). html, jump to the index.php file while the value is passed as a variable into the index.php

7 Common child Profiles

Httpd-autoindex.confapache System Aliases

httpd-default.conf Thread Control *

Httpd-info.conf Status Statistics Page

Httpd-languages.conf Language code *

Httpd-manual.confapache 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

Linux (eight) Apache server

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.