search
HomeDatabaseMysql TutorialApache服务器配置全攻略(一)

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

Jun 07, 2016 pm 03:11 PM
apacheComplete strategyserverConfiguration

Apache 服务器 的设置文件位于/usr/local/apache/conf/目录下,传统上使用三个 配置 文件httpd.conf,access.conf和srm.conf,来 配置 Apache 服务器 的行为。 httpd.conf提供了最基本的 服务器 配置 ,是对守护程序httpd如何运行的技术描述;srm.conf是 服务

    Apache服务器的设置文件位于/usr/local/apache/conf/目录下,传统上使用三个配置文件httpd.conf,access.conf和srm.conf,来配置Apache服务器的行为。


httpd.conf提供了最基本的服务器配置,是对守护程序httpd如何运行的技术描述;srm.conf是服务器的资源映射文件,告诉服务器各种文件的MIME类型,以及如何支持这些文件;access.conf用于配置服务器的访问权限,控制不同用户和计算机的访问限制;这三个配置文件控制着服务器的各个方面的特性,因此为了正常运行服务器便需要设置好这三个文件。


  除了这三个设置文件之外,Apache还使用mime.types文件用于标识不同文件

对应的MIME类型, magic文件设置不同MIME类型文件的一些特殊标识,使得Apache 服务器从文档后缀不能判断出文件的MIME 类型时,能通过文件内容中的这些特殊标记来判断文档的MIME类型。


bash-2.02$ ls -l /usr/local/apache/conf

total 100

-rw-r--r-- 1 root wheel 348 Apr 16 16:01 access.conf

-rw-r--r-- 1 root wheel 348 Feb 13 13:33 access.conf.default

-rw-r--r-- 1 root wheel 30331 May 26 08:55 httpd.conf

-rw-r--r-- 1 root wheel 29953 Feb 13 13:33 httpd.conf.default

-rw-r--r-- 1 root wheel 12441 Apr 19 15:42 magic

-rw-r--r-- 1 root wheel 12441 Feb 13 13:33 magic.default

-rw-r--r-- 1 root wheel 7334 Feb 13 13:33 mime.types

-rw-r--r-- 1 root wheel 383 May 13 17:01 srm.conf

-rw-r--r-- 1 root wheel 357 Feb 13 13:33 srm.conf.default


  事实上当前版本的Apache将原来httpd.conf、srm.conf与access.conf中的所有配置参数均放在了一个配置文件httpd.conf中,只是为了与以前的版本兼容的原因(使用这三个设置文件的方式来源于NCSA-httpd),才使用三个配置文件。而提供的access.conf和srm.conf文件中没有具体的设置。


  由于在新版本的Apache中,所有的设置都被放在了httpd.conf中,因此只需要调整这个文件中的设置。以下使用缺省提供的httpd.conf为例,解释Apache服

务器的各个设置选项。然而不必因为它提供设置的参数太多而烦恼,基本上这些

参数都很明确,也可以不加改动运行Apache服务器。但如果需要调整Apache服务

器的性能,以及增加对某种特性的支持,就需要了解这些设置参数的含义。


  关于Apache服务器的性能,在Internet上存在很大的争议,基本上使用Apache的使用者几乎都不怀疑它的优秀性能,Apache也支撑了很多著名的高负载的网站,但是在商业机构的评测中,Apache往往得分不高。很多人指出,在这些评测中,商业Web服务器及其操作系统往往由其专业公司的工程师进行过性能调整,而Free 的操作系统和Web服务器往往就使用其缺省配置或仅仅作很小的更改。需要指出的是,除了操作系统的性能调整之外,Apache 服务器本身的缺省配置绝不是最优化和最高效的,而是要适应几乎所有种类操作系统、所有种类硬件下的设置,多平台的软件不可能为特定平台和特定硬件提供最优化的缺省配置。因此要使用Apache的时候,性能调整是必不可少的。


  在商业评测中忽略了的另一个事实是,评测时往往对不同种类的功能进行比

较,例如使用Apache的标准CGI 的性能与ISAPI,NSAPI等服务器端API比较,事实上Apache服务器与此可以比较的功能为modperl ,FastCGI,与ASP类似的功能为PHP等等,只不过由于Apache的开放模式,这些功能是由独立的开发组,作为独立的模块来实现的。但是在评测中,测试人员没有加入相应的模块评测其性能。


HTTP守护进程的运行参数


  httpd.conf中首先定义了一些httpd守护进程运行时需要的参数,来决定其运行方式和运行环境。


  ServerType standalone

  ServerType定义服务器的启动方式,缺省值为独立方式standalone,httpd

服务器将由其本身启动,并驻留在主机中监视连接请求。在Linux下将在启动文件 /etc/rc.d/rc.local/init.d/apache中自动启动Web服务器,这种方式是推荐设置。

  启动Apache服务器的另一种方式是inet方式,使用超级服务器inetd监视连接请求并启动服务器。当需要使用inetd启动方式时,便需要更改为这个设置,并屏蔽/etc/rc.d/rc.local/init.d/apache文件,以及更改/etc/inetd.conf并重起inetd,那么Apache就能从inetd中启动了。

  两种方式的区别是独立方式是由服务器自身管理自己的启动进程,这样在启

动时能立即启动服务器的多个副本,每个副本都驻留在内存中,一有连接请求不需要生成子进程就可以立即进行处理,对于客户浏览器的请求反应更快,性能较

高。而 inetd方式要由inetd发现有连接请求后才去启动http服务器,由于inetd 要监听太多的端口,因此反应较慢、效率较低,但节约了没有连接请求时Web服务器占用的资源。因此inetd方式只用于偶尔被访问并且不要求访问速度的服务器上。事实上inetd方式不适合http的突发和多连接的特性,因为一个页面可能包含多个图象,而每个图象都会引起一个连接请求,即使虽然访问人数造成教少,但瞬间的连接请求并不少,这就受到inetd性能的限制,甚至会影响由inetd启动的其他服务器程序。


  ServerRoot "/usr/local"

  ServerRoot用于指定守护进程httpd的运行目录,httpd在启动之后将自动将

进程的当前目录改变为这个目录,因此如果设置文件中指定的文件或目录是相对路径,那么真实路径就位于这个ServerRoot定义的路径之下。

  由于httpd会经常进行并发的文件操作,就需要使用加锁的方式来保证文件操作不冲突,由于NFS文件系统在文件加锁方面能力有限,因此这个目录应该是本地磁盘文件系统,而不应该使用NFS文件系统。


  #LockFile /var/run/httpd.lock

  LockFile参数指定了httpd守护进程的加锁文件,一般不需要设置这个参数, Apache服务器将自动在ServerRoot下面的路径中进行操作。但如果ServerRoot为NFS文件系统,便需要使用这个参数指定本地文件系统中的路径。


  PidFile /var/run/httpd.pid

  PidFile指定的文件将记录httpd守护进程的进程号,由于httpd能自动复制其自身,因此系统中有多个httpd进程,但只有一个进程为最初启动的进程,它为其他进程的父进程,对这个进程发送信号将影响所有的httpd进程。PidFILE定义的文件中就记录httpd父进程的进程号。


  ScoreBoardFile /var/run/httpd.scoreboard

  httpd使用ScoreBoardFile来维护进程的内部数据,因此通常不需要改变这个参数,除非管理员想在一台计算机上运行几个Apache服务器,这时每个Apache服务器都需要独立的设置文件htt pd.conf,并使用不同的ScoreBoardFile。


  #ResourceConfig conf/srm.conf

  #AccessConfig conf/access.conf

  这两个参数ResourceConfig和AccessConfig,就用于和使用 srm.conf 和 access.conf 设置文件的老版本Apache兼容。如果没有兼容的需要,可以将对应的设置文件指定为/dev/null,这将表示不存在其他设置文件,而仅使用httpd.conf 一个文件来保存所有的设置选项。


  Timeout 300

  Timeout定义客户程序和服务器连接的超时间隔,超过这个时间间隔(秒)后服务器将断开与客户机的连接。


  KeepAlive On

  在HTTP 1.0中,一次连接只能作传输一次HTTP请求,而KeepAlive参数用于支持HTTP 1.1版本的一次连接、多次传输功能,这样就可以在一次连接中传递多个HTTP请求。虽然只有较新的浏览器才支持这个功能,但还是打开使用这个选项。


  MaxKeepAliveRequests 100

  MaxKeepAliveRequests为一次连接可以进行的HTTP请求的最大请求次数。将

其值设为0将支持在一次连接内进行无限次的传输请求。事实上没有客户程序在一次连接中请求太多的页面,通常达不到这个上限就完成连接了。


  KeepAliveTimeout 15

  KeepAliveTimeout测试一次连接中的多次请求传输之间的时间,如果服务器

已经完成了一次请求,但一直没有接收到客户程序的下一次请求,在间隔超过了

这个参数设置的值之后,服务器就断开连接。
Statement
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
How does MySQL index cardinality affect query performance?How does MySQL index cardinality affect query performance?Apr 14, 2025 am 12:18 AM

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

MySQL: Resources and Tutorials for New UsersMySQL: Resources and Tutorials for New UsersApr 14, 2025 am 12:16 AM

The MySQL learning path includes basic knowledge, core concepts, usage examples, and optimization techniques. 1) Understand basic concepts such as tables, rows, columns, and SQL queries. 2) Learn the definition, working principles and advantages of MySQL. 3) Master basic CRUD operations and advanced usage, such as indexes and stored procedures. 4) Familiar with common error debugging and performance optimization suggestions, such as rational use of indexes and optimization queries. Through these steps, you will have a full grasp of the use and optimization of MySQL.

Real-World MySQL: Examples and Use CasesReal-World MySQL: Examples and Use CasesApr 14, 2025 am 12:15 AM

MySQL's real-world applications include basic database design and complex query optimization. 1) Basic usage: used to store and manage user data, such as inserting, querying, updating and deleting user information. 2) Advanced usage: Handle complex business logic, such as order and inventory management of e-commerce platforms. 3) Performance optimization: Improve performance by rationally using indexes, partition tables and query caches.

SQL Commands in MySQL: Practical ExamplesSQL Commands in MySQL: Practical ExamplesApr 14, 2025 am 12:09 AM

SQL commands in MySQL can be divided into categories such as DDL, DML, DQL, DCL, etc., and are used to create, modify, delete databases and tables, insert, update, delete data, and perform complex query operations. 1. Basic usage includes CREATETABLE creation table, INSERTINTO insert data, and SELECT query data. 2. Advanced usage involves JOIN for table joins, subqueries and GROUPBY for data aggregation. 3. Common errors such as syntax errors, data type mismatch and permission problems can be debugged through syntax checking, data type conversion and permission management. 4. Performance optimization suggestions include using indexes, avoiding full table scanning, optimizing JOIN operations and using transactions to ensure data consistency.

How does InnoDB handle ACID compliance?How does InnoDB handle ACID compliance?Apr 14, 2025 am 12:03 AM

InnoDB achieves atomicity through undolog, consistency and isolation through locking mechanism and MVCC, and persistence through redolog. 1) Atomicity: Use undolog to record the original data to ensure that the transaction can be rolled back. 2) Consistency: Ensure the data consistency through row-level locking and MVCC. 3) Isolation: Supports multiple isolation levels, and REPEATABLEREAD is used by default. 4) Persistence: Use redolog to record modifications to ensure that data is saved for a long time.

MySQL's Place: Databases and ProgrammingMySQL's Place: Databases and ProgrammingApr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

MySQL: From Small Businesses to Large EnterprisesMySQL: From Small Businesses to Large EnterprisesApr 13, 2025 am 12:17 AM

MySQL is suitable for small and large enterprises. 1) Small businesses can use MySQL for basic data management, such as storing customer information. 2) Large enterprises can use MySQL to process massive data and complex business logic to optimize query performance and transaction processing.

What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?What are phantom reads and how does InnoDB prevent them (Next-Key Locking)?Apr 13, 2025 am 12:16 AM

InnoDB effectively prevents phantom reading through Next-KeyLocking mechanism. 1) Next-KeyLocking combines row lock and gap lock to lock records and their gaps to prevent new records from being inserted. 2) In practical applications, by optimizing query and adjusting isolation levels, lock competition can be reduced and concurrency performance can be improved.

See all articles

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)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.