13. Windows Server Apache 注意事項

最後更新: 2016-06-14

 

 


Windows Server + Apache 注意事項

 

[1] - Disabling the QoS

We suggest disabling the "Quality of Service" (or QoS) network driver from Microsoft if you primarily use the machine as an Apache Server,

as Apache does not support the QoS extensions to the WinSock API.

[2]

Most Firewall programs, Web Spam filters and other TCP/IP driver-based products (including spyware!) do not correctly implement the entire WinSock API.

The shortcuts taken by the developers of such products cause Apache to fail.

[3]

Apache fall back to more basic (but slower) techniques. This resolves most, but not all of the potential problems.

EnableSendfile Off
EnableMMAP     Off
Win32DisableAcceptEx

Win32DisableAcceptEx

Multi-Processing Module (MPM)

AcceptEx() is a Microsoft WinSock v2 API that provides some performance improvements over the use of the BSD style accept() API in certain circumstances.

Some popular Windows products, typically virus scanning or virtual private network packages,

have bugs that interfere with the proper operation of AcceptEx().

沒有遇到以下 Error 就不用 Disable AcceptEx() - 加 Win32DisableAcceptEx

[error] (730038)An operation was attempted on something that is not a socket.: winnt_accept: AcceptEx failed. Attempting to recover.

 


Module: mpm_winnt

 

mpm_winnt - This Multi-Processing Module is optimized for Windows NT.

It uses a single control process which launches a single child process which in turn creates threads to handle requests

ThreadsPerChild N

This directive sets the number of threads created by each child process.
The child creates these threads at startup and never creates more.

If using an MPM like mpm_winnt, where there is only one child process

This number should be high enough to handle the entire load of the server.

Default:

  • mpm_winnt: 65
  • others: 25

MaxRequestsPerChild N (作用: 防止大量 memory leakage)

After MaxRequestsPerChild requests, the child process will die.
If MaxRequestsPerChild is 0, then the process will never expire. <= 唔建議

 * For KeepAlive requests, only the first request is counted towards this limit.

Default:

  • mpm_winnt: 0
  • other: 10000

Bug ...

... [crit] (OS 6)The handle is invalid.  : master_main: create child process failed. Exiting.

ThreadLimit number

This directive sets the maximum configured value for ThreadsPerChild for the lifetime of the Apache httpd process.
Any attempts to change this directive during a restart will be ignored.
ThreadsPerChild can be modified during a restart up to the value of this directive

If ThreadLimit is set to a value much higher than ThreadsPerChild, extra unused shared memory will be allocated.

Default:

other: 64
mpm_winnt: 1920

ThreadStackSize size

sets the size of the stack (for autodata) of threads which handle client connections and call modules to help process those connections.

In most cases the operating system default for stack size is reasonable, but there are some conditions where it may need to be adjusted:

- On platforms with a relatively small default thread stack size
   (Apache may crash when using some third-party modules which use a relatively large amount of autodata storage.)
 - On platforms where the default thread stack size is significantly larger than necessary for the web server configuration

ReceiveBufferSize & SendBufferSize

The server will set the TCP receive/send buffer size to the number of bytes specified.

If set to the value of 0, the server will use the OS default.

* required to elicit better performance on high speed, high latency connections.

總結

使用以下 Settings 就可以了

<IfModule mpm_winnt_module>
    ThreadsPerChild     64
    MaxRequestsPerChild 2048
</IfModule>

 


Install / Uninstall Service

 

Once you have confirmed that Apache runs correctly as a console application you can install,

control and uninstall the pseudo-service with the same commands as on Windows NT.

# Install Apache as a service

httpd -k install

# 用其他名

httpd -k install -n "MyServiceName"

# 設定不同 service 不同 configure

httpd -k install -n "MyServiceName" -f "c:\files\my.conf"

(-f specifies an absolute or relative path to a particular configuration file)

# uninstall service

httpd -k uninstall

httpd -k uninstall -n "MyServiceName"

# Start / Stop Service

httpd -k stop | start | restart

P.S.

相當於 NET STOP / NET START 指令

# Verify the compiled value

httpd -V

# Registry:

HKEY_LOCAL_MACHINE\SOFTWARE\Apache Group\Apache\

 


Apache + PHP

 

Cannot load D:/php-5.3.29RC1-Win32-VC9-x86/php5apache2_2.dll into server: %1 is not a valid Win32 application.

64bit/32bit 及 vc14 level 必須要相同才可以行到.

 


mpm_winnt 有 Setting

 

<IfModule mpm_winnt.c>
  Win32DisableAcceptEx
  EnableSendfile off
  EnableMMAP off
</IfModule>

Start Log

error.log

[Thu May 17 11:02:50 2018] [notice] Apache/2.2.17 (Win32) PHP/5.3.18 configured -- resuming normal operations
[Thu May 17 11:02:50 2018] [notice] Server built: Oct 18 2010 01:58:12
[Thu May 17 11:02:50 2018] [notice] Parent: Created child process 5292
[Thu May 17 11:02:50 2018] [notice] Disabled use of AcceptEx() WinSock2 API
[Thu May 17 11:02:50 2018] [notice] Child 5292: Child process is running
[Thu May 17 11:02:50 2018] [notice] Child 5292: Acquired the start mutex.
[Thu May 17 11:02:50 2018] [notice] Child 5292: Starting 255 worker threads.
[Thu May 17 11:02:50 2018] [notice] Child 5292: Listening on port 80.

EnableMMAP

Default: On

Use memory-mapping to read files during delivery

EnableSendfile

Default: Off

httpd may use the sendfile support from the kernel to transmit file contents to the client
On: Apache httpd uses sendfile to deliver the file contents without ever reading the file if the OS supports it.
This sendfile mechanism avoids separate read and send operations, and buffer allocations.

With a network-mounted DocumentRoot (e.g., NFS, SMB, CIFS, FUSE),
the kernel may be unable to serve the network file through its own cache.

總結

如果沒有遇到 Error, 建議

  #Win32DisableAcceptEx
  EnableSendfile on
  EnableMMAP on

 


SSLSessionCache (Windows)

 

Log

[warn] Init: Session Cache is not configured [hint: SSLSessionCache]

Setting

# Inter-Process Session Cache
# Configure the SSL Session Cache
# First the mechanism to use and second the expiring timeout (in seconds).
SSLSessionCache              "shmcb:ssl_scache(512000)"
SSLSessionCacheTimeout  300

Checking: /server-status

LoadModule status_module modules/mod_status.so
<IfModule mod_status.c>
    ExtendedStatus On
    <Location /server-status>
        SetHandler server-status
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Location>
</IfModule>

info

........
cache type: SHMCB, shared memory: 512000 bytes, current sessions: 0

 

 

Creative Commons license icon Creative Commons license icon