Linux攻略 关于Apache摆设、设置、优化

 来历:网海拾贝 




摆设 Apache 2.0.48 (查抄Install手册)

  思考到以后要 rewite_url 来使 google 加倍随便收录网站,特意添加了 mod_rewrite 。

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

  建议摆设停止以后不要删除摆设目录,以便以落伍级时运用。

  记得进级前封闭 apache2.0

  编译进程:
  
  代码:

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

  这个例子轮廓是编译了 mod_so,mod_speling 和 openssl 支持。
  异样有别的几种写法
  
  代码:

#./configure --enable-modules=so --enable-modules=speling --enable-modules=rewrite
  
  或许
  
  代码:

#./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 参数
  
  摆设停止后可以用以下命令来查抄启动了那些模块
  
  代码:

  # 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 

  接着,将启动步伐放入开机步伐中去。 如果要启动 ssl 加密网页,则必需经过进程手动启动 apache2.0 (拜见 ssl 部分 )
  
  代码:

# echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local

  参考:

  代码:

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. 

  在 profile 轮廓添加以上的语句来设置途径,使得在 bash 下更随便节制 apachectl, 省去了输出途径的费事。
  
  代码:

# vi /etc/profile
   PATH="  $PATH:usr/local/apache2/bin:”
  
  设置 apache2.0

  代码:

# vi /usr/local/apache2/conf/httpd.conf
  
  设置文件请看文件 httpd.conf (设置文档目录为/home/dalouis/public_html)
  
  代码:

#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 的行加上 #.

  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 的设置效果。
  
  以下是对设置的一编削改:
  
  代码:

# 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

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

  代码:

# 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, 以下是介绍。
  
  代码:

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

  摆设进程

# 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).




版权声明: 原创作品,允许转载,转载时请务必以超链接体式格局标明文章 原始出处 、作者信息和本声明。不然将追查功令责任。

原文地址:https://www.cnblogs.com/zgqjymx/p/1976197.html