http的應用-編譯安裝Apache
阿新 • • 發佈:2018-11-28
http的應用
httpd-2.4: 新特性: (1) MPM支援執行DSO機制;以模組形式按需載入; (2) 支援event MPM; (3) 支援非同步讀寫; (4) 支援每模組及每個目錄分別使用各自的日誌級別; (5) 每請求配置;<If> (6) 增強版的表示式分析器; (7) 支援毫秒級的keepalive timeout; (8) 基於FQDN的虛擬主機不再需要NameVirtualHost指令; (9) 支援使用者自定義變數; 新模組: (1) mod_proxy_fcgi (2) mod_ratelimit (3) mod_remoteip 修改了一些配置機制: 不再支援使用Order, Deny, Allow來做基於IP的訪問控制; 安裝httpd-2.4 httpd依賴於apr-1.4+, apr-util-1.4+, [apr-icon] apr: apache portable runtime CentOS 6: 預設:apr-1.3.9, apr-util-1.3.9 編譯安裝步驟: 1.4+版的apr和apr-util 前提: 安裝開發環境,安裝pcre-devel (1) apr # ./configure --prefix=/usr/local/apr # make && make install (2) apr-util # ./configure --prefix=/usr/local/apr-util --with=/usr/local/apr # make && make install # groupadd -r apache # useradd -r -g apache apahce # ./configure --prefix=/usr/local/apache --sysconf=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork # make && make install 啟動服務: apachectl CentOS 7: 配置檔案: 主配置檔案:/etc/httpd/conf/httpd.conf 模組配置檔案:/etc/httpd/conf.modules.d/*.conf 輔助配置檔案:/etc/httpd/conf.d/*.conf mpm:以DSO機制提供,配置檔案00-mpm.conf 服務控制:systemctl {start|stop|restart|status|reload} httpd.service 配置: (1) 切換使用MPM LoadModule mpm_NAME_module modules/mod_mpm_NAME.so NAME: prefork, event, worker (2) 修改'Main' server的DocumentRoot (3) 基於IP的訪問控制法則 允許所有主機訪問:Require all granted 拒絕所有主機訪問:Require all deny 控制特定IP訪問: Require ip IPADDR:授權指定來源地址的主機訪問 Require not ip IPADDR:拒絕指定來源地址的主機訪問 IPADDR: IP: 172.16.100.2 Network/mask: 172.16.0.0/255.255.0.0 Network/Length: 172.16.0.0/16 Net: 172.16 控制特定主機(HOSTNAME)訪問 Require host HOSTNAME Require not host HOSTNAME HOSTNAME: FQDN: 特定主機 DOMAIN:指定域內的所有主機 <RequireAll> Require all granted Require not ip 10.252.46.165 </RequireAll> (4) 虛擬主機 基於IP、Port和FQDN都支援; 基於FQDN的不再需要NameVirtualHost指令; (5) ssl 啟用模組: LoadModule ssl_module modules/mod_ssl.so (6) CentOS 6 服務指令碼 #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: The Apache HTTP Server is an efficient and extensible \ # server implementing the current HTTP standards. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd/httpd.pid # ### BEGIN INIT INFO # Provides: httpd # Required-Start: $local_fs $remote_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Should-Start: distcache # Short-Description: start and stop Apache HTTP Server # Description: The Apache HTTP Server is an extensible server # implementing the current HTTP standards. ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=/usr/local/apache/bin/httpd prog=httpd pidfile=${PIDFILE-/var/run/httpd/httpd24.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd24} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } # When stopping httpd, a delay (of default 10 second) is required # before SIGKILLing the httpd parent; this gives enough time for the # httpd parent to SIGKILL any errant children. stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=6 echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else # Force LSB behaviour from killproc LSB=1 killproc -p ${pidfile} $httpd -HUP RETVAL=$? if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart|try-restart) if status -p ${pidfile} $httpd >&/dev/null; then stop start fi ;; force-reload|reload) reload ;; graceful|help|configtest|fullstatus) $apachectl
[email protected] RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2 esac exit $RETVAL