服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

服务器之家 - 服务器系统 - Linux - Linux系统下Apache安装、配置、优化

Linux系统下Apache安装、配置、优化

2019-10-13 16:03Linux之家 Linux

安装Apache 2.0.48 (查看Install手册) 考虑到以后要 rewite_url 来使 google 更加容易收录网站,特地添加了 mod_rewrite 。 同时为了限制流量,特别加了 mod_limitpcnn.c 补丁 , 所以多了一个 --enable-forward 选项。 建议安装完毕以后不要删除安装目录

安装Apache 2.0.48 (查看Install手册)

考虑到以后要 rewite_url 来使 google 更加容易收录网站,特地添加了 mod_rewrite 。

同时为了限制流量,特别加了 mod_limitpcnn.c 补丁 , 所以多了一个 --enable-forward 选项。

建议安装完毕以后不要删除安装目录,以便以后升级时使用。

记得升级前关闭 apache2.0

编译过程:

代码:

这个例子里面是编译了 mod_so,mod_speling 和 openssl 支持。

同样有另外几种写法

代码:

接着,将启动程序放入开机程序中去。 如果要启动 ssl 加密网页,则必须通过手动启动 apache2.0 (参见 ssl 部分 )

代码:

代码:

在 profile 里面添加以上的语句来设置路径,使得在 bash 下更容易控制 apachectl, 省去了输入路径的麻烦。

代码:

Xiyang 的配置

我用的: mod_limitipconn, mod_expires, mod_gzip, mod_php4, mod_so, mod_access, mod_alias, mod_userdir, mod_dir, mod_autoindex, mod_status, mod_mime, mod_log_config, http_core

关于超时的问题

在我编写好所有的产品查看页面的时候,经常会出现因为超时,或者流量过大 ,apache 停止工作的问题,原因有二,一是代码的不科学性,二是 apache 的设置问题。

以下是对设置的一点改动:

代码:

• 记录访问者的 HTTP-REFERER 和 AGENT, 有助于统计来者是通过什么搜索引擎找到我们的网站的。 或者在原有的CustomLog行,将参数由 common 改成 combined

代码:

安装过程

# lynx http://dominia.org/djao/limit/mod_limitipconn-0.22.tar.gz 
  # tar -zxvf mod_limitipconn-0.22.tar.gz 
  # cd httpd-2.0.48 
  # patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff 
  patching file configure.in 
  Hunk #1 succeeded at 373 (offset 55 lines). 
  patching file include/scoreboard.h 
  patching file modules/generators/mod_status.c 
  Hunk #1 succeeded at 746 (offset -1 lines). 
##Instructions for building DSO with proxy tracking: 
  # tar xzvf httpd-2.0.39.tar.gz 
  # tar xzvf mod_limitipconn-0.22.tar.gz 
  # cd httpd-2.0.39 
  # patch -p1 < ../mod_limitipconn-0.22/apachesrc.diff 
  # ./buildconf 
  # ./configure --enable-so --enable-speling --enable-rewrite 
--with-ssl=/usr/local/ssl --enable-forward 
  # make 
  # make install 
  # cd ../mod_limitipconn-0.22 
  # PATH=/usr/local/apache2/bin:$PATH 
  # make install 
# If you would like to have agent and referer logfiles, 
  # uncomment the following directives. 
  CustomLog logs/referer_log referer       
  CustomLog logs/agent_log agent 
  CustomLog logs/www.domain.com-access_log combined

使用 mod_limitipconn.c 来限制 apache 的并发数

Package: http://dominia.org/djao/limit/这里的安装建议使用动态 DSO 并 patch apache2.0, 以使得 apache2.0 可以认识在代理后方的 IP 。但是要 重新编译 apache2.0, 以下是介绍。

代码:

# KeepAlive: Whether or not to allow persistent connections(more than 
  # one request per connection). Set to "Off" to deactivate. 
  
  # KeepAlive Off 
  
  # MaxKeepAliveRequests: The maximum number of requests to allow 
  # during a persistent connection. Set to 0 to allow an unlimited amount. 
  # We recommend you leave this number high, for maximum performance. 
  
  # MaxKeepAliveRequests 0 
  
  # KeepAliveTimeout: Number of seconds to wait for the next request 
  # from the same client on the same connection. 
  
  # KeepAliveTimeout 0 
#chmod 755 – R /home/dalouis/ 

设置目录的可读性为 drwxr-xr-x(755), 否则会出现 "Forbidden You don't have permission to access / on this server."

一些关于安全性的配置:

考虑到 cgi-bin 的安全性问题,我们暂时将 cgi-bin 去掉。将所有 httpd.conf 中的所有关于 cgi-bin 的行加上 #.

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

配置文件请看文件 httpd.conf (设置文档目录为/home/dalouis/public_html)

代码:

# vi /etc/profile 
  PATH=" $PATH:usr/local/apache2/bin:”

配置 apache2.0

代码:

If you want your server to continue running after a system reboot , 
  you should add a call to apachectl to your system startup files (typically rc.local or 
  a file in an rc.N directory). This will start Apache as root. Before doing this ensure 
  that your server is properly configured for security and access restrictions. 
# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local 

参考:

  # apachectl -l 
  Compiled in modules: 
  core.c 
  mod_access.c 
  mod_auth.c 
  mod_include.c 
  mod_log_config.c 
  mod_env.c 
  mod_setenvif.c 
  prefork.c 
  http_core.c 
  mod_mime.c 
  mod_status.c 
  mod_autoindex.c 
  mod_asis.c 
  mod_cgi.c 
  mod_negotiation.c 
  mod_dir.c mod_imap.c 
  mod_actions.c 
  mod_speling.c 
  mod_userdir.c 
  mod_alias.c 
  mod_rewrite.c 
  mod_so.c 
#./configure --enable-modules=”so speling” 

--enable-MODULE[=shared] 编译并包含模块 MODULE. MODULE 是文档中去掉” _module ”的模块名。要将一个模块编译成为 DSO, 需要加 -shared 选项 , 即 --enable-mods-shared 。 (查看 MODULE 手册)

注意 :"如果希望核心能够装载 DSO,而不实际编译任何动态模块,则要明确指定 --enable-modules=so 或者 --enable-so" (查看 DSO 手册),所以前面的顺序不能交换顺序。 查看所有apache 的 configure 参数

安装完毕后可以用以下命令来查看启动了那些模块

代码:

#./configure --enable-modules=so --enable-modules=speling --enable-modules=rewrite 

或者

代码:

#./configure --enable-so --enable-speling --enable-rewrite
 --with-ssl=/usr/local/ssl --enable-forward 
  # make 
  # make install 

 

延伸 · 阅读

精彩推荐
  • LinuxLinux上设置用户通过SFTP访问目录的权限的方法

    Linux上设置用户通过SFTP访问目录的权限的方法

    这篇文章主要介绍了Linux上设置用户通过SFTP访问目录的权限的方法,SFTP可以理解为使用SSH协议进行FTP传输的协议,因而同时要对OpenSSH进行相关设置,需要的朋...

    OSChina10022019-06-19
  • LinuxLinux中环境变量配置的步骤详解

    Linux中环境变量配置的步骤详解

    Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登录到系统的用户都要读取的系统变量,而用户级的环境变量则是该用户使用系统时加载的...

    Myths7882022-02-10
  • Linux详解Linux系统下PXE服务器的部署过程

    详解Linux系统下PXE服务器的部署过程

    这篇文章主要介绍了Linux系统下PXE服务器的部署过程,包括对PXE的API架构作了一个基本的简介,需要的朋友可以参考下...

    运维之道9812019-07-04
  • Linux手把手教您在 Linux 上使用 GPG 加解密文件

    手把手教您在 Linux 上使用 GPG 加解密文件

    在本教程中,我将告诉你如何用 GPG 加密和解密文件。这是一个简单的教程,你可以在你的 Linux 系统上尝试所有的练习。这将帮助你练习 GPG 命令,并在你...

    Linux中国6962021-12-15
  • Linuxlinux中rmdir命令使用详解(删除空目录)

    linux中rmdir命令使用详解(删除空目录)

    今天学习一下linux中命令: rmdir命令。rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的 ...

    linux命令大全5372019-11-19
  • LinuxLinux lnmp下无法使用mail发邮件的两种解决方法

    Linux lnmp下无法使用mail发邮件的两种解决方法

    在配置了lnmp环境后,出现了mail函数不能发送邮件的问题,其实有两种方法,一是使用sendmail组件,而是使用postfix。下面为大家一一介绍下 ...

    Linux之家4042019-09-17
  • LinuxLinux常用的日志文件和常用命令

    Linux常用的日志文件和常用命令

    成功地管理任何系统的关键之一,是要知道系统中正在发生什么事。 Linux 中提供了异常日志,并且日志的细节是可配置的。Linux 日志都以明文形式存储,所...

    Linux教程网2632020-04-18
  • Linux确保Linux系统安全的前提条件 漏洞防护

    确保Linux系统安全的前提条件 漏洞防护

    Linux 作为开放式的操作系统受到很多程序员的喜爱,很多高级程序员都喜欢编写Linux操作系统的相关软件。这使得Linux操作系统有着丰富的软件支持,还有无...

    Linux之家2642020-04-11