Home php教程 php手册 Apache服务器配置全攻略(八)

Apache服务器配置全攻略(八)

Jun 21, 2016 am 09:08 AM
apache

apache|服务器|攻略

作者:王波

用于设置访问控制的设置主要是针对目录和文件进行设置的,然而也可以针对不同的URL进行访问控制的设置,这样就不必担心ScriptAlias、Alias是否将路径设置到了受控制的目录之外了。针对URL进行控制的语句为 Location语句,这样不但能对服务器上的文件、CGI提供保护,此外,它还能保护不能找到对应文件,而是由服务器本身提供的特殊功能URL。http://servername/server-status用于报告当前Apache服务器的状态,http://servername/server-info用于报告Apache 服务器的统计信息。与此相关的设置还有ExtendedStatus参数,可以让服务器输出更详细的的报告。


#

#ProxyRequests On

#

#

# Order deny,allow

# Deny from all

# Allow from .your_domain.com

#

#ProxyVia On

#CacheRoot "/www/proxy"

#CacheSize 5

#CacheGcInterval 4

#CacheMaxExpire 24

#CacheLastModifiedFactor 0.1

#CacheDefaultExpire 1

#NoCache a_domain.com another_domain.edu joes.garage_sale.com


#


  Apache服务器本身就具备代理的功能,然而这要求加载入mod_proxy模块。这能使用IfModule语句进行判断,如果存在mod_proxy模块,就使用ProxyRequests打开代理支持。此后的Directory用于设置对Proxy功能的访问权限设置,以及用于设置缓冲的各个参数设置。


虚拟主机

#NameVirtualHost 12.34.56.78:80

#NameVirtualHost 12.34.56.78

#

# ServerAdmin webmaster@host.some_domain.com

# DocumentRoot /www/docs/host.some_domain.com

# ServerName host.some_domain.com

# ErrorLog logs/host.some_domain.com-error_log

# CustomLog logs/host.some_domain.com-access_log common

#


#


  缺省设置文件中的这些内容是用于设置命名基础的虚拟主机服务器时使用。

其中NameVirtualHost 来指定虚拟主机使用的IP地址,这个IP地址将对应多个 DNS名字,如果Apache使用了Listen 参数控制了多个端口,那么就可以在这里加上端口号以进一步进行区分对不同端口的不同连接请求。此后,使用 VirtualHost 语句,使用NameVirtualHost指定的IP地址作参数,对每个名字都定义对应的虚拟主机设置。

  虚拟主机是在一台Web服务器上,可以为多个单独域名提供Web服务,并且每个域名都完全独立,包括具有完全独立的文档目录结构及设置,这样域名之间完全独立,不但使用每个域名访问到的内容完全独立,并且使用另一个域名无法访

问其他域名提供的网页内容。

  虚拟主机的概念对于ISP来讲非常有用,因为虽然一个组织可以将自己的网页挂在具备其他域名的服务器上的下级往址上,但使用独立的域名和根网址更为正式,易为众人接受。传统上,必须自己设立一台服务器才能达到单独域名的目的,然而这需要维护一个单独的服务器,很多小单位缺乏足够的维护能力,更为合适的方式是租用别人维护的服务器。ISP也没有必要为一个机构提供一个单独的服务器,完全可以使用虚拟主机能力,使服务器为多个域名提供Web服务,而且不同的服务互不干扰,对外就表现为多个不同的服务器。

  有两种设定虚拟主机的方式,一种是基于HTTP 1.0标准,需要一个具备多IP

地址的服务器,再配置DNS 服务器,给每个IP地址以不同的域名,最后才能配置Apache的配置文件,使服务器对不同域名返回不同的Web文档。由于这需要使用额外的IP地址,对每个要提供服务的域名都要使用单独的IP地址,因此这种方式实现起来问题较多。

  可以在一个网络界面上绑定多个IP地址,Linux下需要使用ifconfig的 alias参数来进行这个配置,但此时会影响网络性能。

  HTTP 1.1标准在协议中规定了对浏览器和服务器通信时,服务器能够跟踪浏

览器请求的是哪个主机名字。因此可以利用这个新特性,使用更轻松的方式设定

虚拟主机。这种方式不需要额外的IP地址,但需要新版本的浏览器支持。这种方式已经成为建立虚拟主机的标准方式。

  要建立非IP基础的虚拟主机,多个域名是不可少的配置,因为每个域名就对

应一个要服务的虚拟主机。因此需要更改DNS服务器的配置,为服务器增加多个C NAME选项,如:


linux IN A 192.168.1.64

vhost1 IN CNAME linux

vhost2 IN CNAME linux


 基本的设置选项都是为了linux主机设定的,如果要为vhost1和vhost2设定

虚拟主机,就要使用VirtualHost语句定义不同的选项,在语句中可以使用配置文件前面中的大部分选项,而可以重新定义几乎所有的针对服务器的设置。


NameVirtualHost 192.168.1.64


DocumentRoot /www/data

ServerName linux.example.org.cn


DocumentRoot /vhost1

ServerName vhost1.example.org.cn


DocumentRoot /vhost2

ServerName vhost2.example.org.cn


  这里需要注意的是,VirtualHost的参数地址一定要和NameVirtualHost定义的地址相一致,必须保证所有的值严格一致,Apache服务器才承认这些定义是为这个IP地址定义的虚拟主机。

  此外,定义过NameVirtualHost之后,那么对这个IP地址的访问都被区分不同的虚拟主机进行处理,而对其他IP地址的访问,例如127.0.0.1,才应用前面定义的缺省选项。




Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP Framework Performance Comparison: The Ultimate Showdown of Speed ​​vs. Efficiency PHP Framework Performance Comparison: The Ultimate Showdown of Speed ​​vs. Efficiency Apr 30, 2024 pm 12:27 PM

According to benchmarks, Laravel excels in page loading speed and database queries, while CodeIgniter excels in data processing. When choosing a PHP framework, you should consider application size, traffic patterns, and development team skills.

How to conduct concurrency testing and debugging in Java concurrent programming? How to conduct concurrency testing and debugging in Java concurrent programming? May 09, 2024 am 09:33 AM

Concurrency testing and debugging Concurrency testing and debugging in Java concurrent programming are crucial and the following techniques are available: Concurrency testing: Unit testing: Isolate and test a single concurrent task. Integration testing: testing the interaction between multiple concurrent tasks. Load testing: Evaluate an application's performance and scalability under heavy load. Concurrency Debugging: Breakpoints: Pause thread execution and inspect variables or execute code. Logging: Record thread events and status. Stack trace: Identify the source of the exception. Visualization tools: Monitor thread activity and resource usage.

How to add a server in eclipse How to add a server in eclipse May 05, 2024 pm 07:27 PM

To add a server to Eclipse, follow these steps: Create a server runtime environment Configure the server Create a server instance Select the server runtime environment Configure the server instance Start the server deployment project

The evasive module protects your website from application layer DOS attacks The evasive module protects your website from application layer DOS attacks Apr 30, 2024 pm 05:34 PM

There are a variety of attack methods that can take a website offline, and the more complex methods involve technical knowledge of databases and programming. A simpler method is called a "DenialOfService" (DOS) attack. The name of this attack method comes from its intention: to cause normal service requests from ordinary customers or website visitors to be denied. Generally speaking, there are two forms of DOS attacks: the third and fourth layers of the OSI model, that is, the network layer attack. The seventh layer of the OSI model, that is, the application layer attack. The first type of DOS attack - the network layer, occurs when a large number of of junk traffic flows to the web server. When spam traffic exceeds the network's ability to handle it, the website goes down. The second type of DOS attack is at the application layer and uses combined

Application of algorithms in the construction of 58 portrait platform Application of algorithms in the construction of 58 portrait platform May 09, 2024 am 09:01 AM

1. Background of the Construction of 58 Portraits Platform First of all, I would like to share with you the background of the construction of the 58 Portrait Platform. 1. The traditional thinking of the traditional profiling platform is no longer enough. Building a user profiling platform relies on data warehouse modeling capabilities to integrate data from multiple business lines to build accurate user portraits; it also requires data mining to understand user behavior, interests and needs, and provide algorithms. side capabilities; finally, it also needs to have data platform capabilities to efficiently store, query and share user profile data and provide profile services. The main difference between a self-built business profiling platform and a middle-office profiling platform is that the self-built profiling platform serves a single business line and can be customized on demand; the mid-office platform serves multiple business lines, has complex modeling, and provides more general capabilities. 2.58 User portraits of the background of Zhongtai portrait construction

How to deploy and maintain a website using PHP How to deploy and maintain a website using PHP May 03, 2024 am 08:54 AM

To successfully deploy and maintain a PHP website, you need to perform the following steps: Select a web server (such as Apache or Nginx) Install PHP Create a database and connect PHP Upload code to the server Set up domain name and DNS Monitoring website maintenance steps include updating PHP and web servers, and backing up the website , monitor error logs and update content.

How to implement PHP security best practices How to implement PHP security best practices May 05, 2024 am 10:51 AM

How to Implement PHP Security Best Practices PHP is one of the most popular backend web programming languages ​​used for creating dynamic and interactive websites. However, PHP code can be vulnerable to various security vulnerabilities. Implementing security best practices is critical to protecting your web applications from these threats. Input validation Input validation is a critical first step in validating user input and preventing malicious input such as SQL injection. PHP provides a variety of input validation functions, such as filter_var() and preg_match(). Example: $username=filter_var($_POST['username'],FILTER_SANIT

How to leverage Kubernetes Operator simplifiy PHP cloud deployment? How to leverage Kubernetes Operator simplifiy PHP cloud deployment? May 06, 2024 pm 04:51 PM

KubernetesOperator simplifies PHP cloud deployment by following these steps: Install PHPOperator to interact with the Kubernetes cluster. Deploy the PHP application, declare the image and port. Manage the application using commands such as getting, describing, and viewing logs.

See all articles