NGINX自动脚本之 auto_options 源码分析

来源:互联网 发布:湖南软件学院 编辑:程序博客网 时间:2024/04/30 05:46

#本文件由configure文件引用,纯shell脚本,主要用来接收一些安装时的参数,help=no

NGX_PREFIX=NGX_SBIN_PATH=NGX_CONF_PREFIX=NGX_CONF_PATH=NGX_ERROR_LOG_PATH=NGX_PID_PATH=NGX_LOCK_PATH=NGX_USER=NGX_GROUP=

CC=${CC:-gcc}CPP=NGX_OBJS=objs

NGX_DEBUG=NONGX_CC_OPT=NGX_LD_OPT=CPU=NO

NGX_RPATH=NO

NGX_TEST_BUILD_DEVPOLL=NONGX_TEST_BUILD_EVENTPORT=NONGX_TEST_BUILD_EPOLL=NONGX_TEST_BUILD_RTSIG=NONGX_TEST_BUILD_SOLARIS_SENDFILEV=NO

NGX_PLATFORM=NGX_WINE=

EVENT_FOUND=NO

EVENT_RTSIG=NOEVENT_SELECT=NOEVENT_POLL=NOEVENT_AIO=NO

USE_THREADS=NO

NGX_IPV6=NO

HTTP=YES

NGX_HTTP_LOG_PATH=NGX_HTTP_CLIENT_TEMP_PATH=NGX_HTTP_PROXY_TEMP_PATH=NGX_HTTP_FASTCGI_TEMP_PATH=

HTTP_CACHE=YESHTTP_CHARSET=YESHTTP_GZIP=YESHTTP_SSL=NOHTTP_SSI=YESHTTP_POSTPONE=NOHTTP_REALIP=NOHTTP_XSLT=NOHTTP_IMAGE_FILTER=NOHTTP_SUB=NOHTTP_ADDITION=NOHTTP_DAV=NOHTTP_ACCESS=YESHTTP_AUTH_BASIC=YESHTTP_USERID=YESHTTP_AUTOINDEX=YESHTTP_RANDOM_INDEX=NOHTTP_STATUS=NOHTTP_GEO=YESHTTP_GEOIP=NOHTTP_MAP=YESHTTP_REFERER=YESHTTP_REWRITE=YESHTTP_PROXY=YESHTTP_FASTCGI=YESHTTP_PERL=NOHTTP_MEMCACHED=YESHTTP_LIMIT_ZONE=YESHTTP_LIMIT_REQ=YESHTTP_EMPTY_GIF=YESHTTP_BROWSER=YESHTTP_SECURE_LINK=NOHTTP_FLV=NOHTTP_GZIP_STATIC=NOHTTP_UPSTREAM_IP_HASH=YES

# STUBHTTP_STUB_STATUS=NO

MAIL=NOMAIL_SSL=NOMAIL_POP3=YESMAIL_IMAP=YESMAIL_SMTP=YES

NGX_ADDONS=

USE_PCRE=NOPCRE=NONEPCRE_OPT=

USE_OPENSSL=NOOPENSSL=NONE

USE_MD5=NOMD5=NONEMD5_OPT=MD5_ASM=NO

USE_SHA1=NOSHA1=NONESHA1_OPT=SHA1_ASM=NO

USE_ZLIB=NOZLIB=NONEZLIB_OPT=ZLIB_ASM=NO

USE_PERL=NONGX_PERL=perl

USE_LIBXSLT=NOUSE_LIBGD=NO

NGX_GOOGLE_PERFTOOLS=NONGX_CPP_TEST=NO

NGX_CPU_CACHE_LINE=

opt=#以上全是变量初始化,有的赋值值,有的未赋值,shell脚本的赋值与其他脚本不同,不可以乱加空格for option #这是shell脚本的一个特点,for 后面可以省略要遍历的变量,这时,表示在遍历$@,即用户传入的所有变量组合do opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`" #sed用法较特别,首先sed是一个管道函数, 其次,-e表示后面是一个正则,sed的后面的字串会直接被执行#以上正则是将所有参数逐个处理成 --abc=cccc --aaa=ddd 这样的形式,算是统一参数 case "$option" in -*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;#取出一个参数后面的值,如--abc=ccc, 只取出ccc *) value="" ;; esac

case "$option" in #以下对参数名进行匹配,并对全局变量赋值 --help) help=yes ;;

--prefix=) NGX_PREFIX="!" ;; --prefix=*) NGX_PREFIX="$value" ;; --sbin-path=*) NGX_SBIN_PATH="$value" ;; --conf-path=*) NGX_CONF_PATH="$value" ;; --error-log-path=*) NGX_ERROR_LOG_PATH="$value";; --pid-path=*) NGX_PID_PATH="$value" ;; --lock-path=*) NGX_LOCK_PATH="$value" ;; --user=*) NGX_USER="$value" ;; --group=*) NGX_GROUP="$value" ;;

--crossbuild=*) NGX_PLATFORM="$value" ;;

--builddir=*) NGX_OBJS="$value" ;;

--with-rtsig_module) EVENT_RTSIG=YES ;; --with-select_module) EVENT_SELECT=YES ;; --without-select_module) EVENT_SELECT=NONE ;; --with-poll_module) EVENT_POLL=YES ;; --without-poll_module) EVENT_POLL=NONE ;; --with-aio_module) EVENT_AIO=YES ;;

#--with-threads=*) USE_THREADS="$value" ;; #--with-threads) USE_THREADS="pthreads" ;;

--with-ipv6) NGX_IPV6=YES ;;

--without-http) HTTP=NO ;; --without-http-cache) HTTP_CACHE=NO ;;

--http-log-path=*) NGX_HTTP_LOG_PATH="$value" ;; --http-client-body-temp-path=*) NGX_HTTP_CLIENT_TEMP_PATH="$value" ;; --http-proxy-temp-path=*) NGX_HTTP_PROXY_TEMP_PATH="$value" ;; --http-fastcgi-temp-path=*) NGX_HTTP_FASTCGI_TEMP_PATH="$value" ;;

--with-http_ssl_module) HTTP_SSL=YES ;; --with-http_realip_module) HTTP_REALIP=YES ;; --with-http_addition_module) HTTP_ADDITION=YES ;; --with-http_xslt_module) HTTP_XSLT=YES ;; --with-http_image_filter_module) HTTP_IMAGE_FILTER=YES ;; --with-http_geoip_module) HTTP_GEOIP=YES ;; --with-http_sub_module) HTTP_SUB=YES ;; --with-http_dav_module) HTTP_DAV=YES ;; --with-http_flv_module) HTTP_FLV=YES ;; --with-http_gzip_static_module) HTTP_GZIP_STATIC=YES ;; --with-http_random_index_module) HTTP_RANDOM_INDEX=YES ;; --with-http_secure_link_module) HTTP_SECURE_LINK=YES ;;

--without-http_charset_module) HTTP_CHARSET=NO ;; --without-http_gzip_module) HTTP_GZIP=NO ;; --without-http_ssi_module) HTTP_SSI=NO ;; --without-http_userid_module) HTTP_USERID=NO ;; --without-http_access_module) HTTP_ACCESS=NO ;; --without-http_auth_basic_module) HTTP_AUTH_BASIC=NO ;; --without-http_autoindex_module) HTTP_AUTOINDEX=NO ;; --without-http_status_module) HTTP_STATUS=NO ;; --without-http_geo_module) HTTP_GEO=NO ;; --without-http_map_module) HTTP_MAP=NO ;; --without-http_referer_module) HTTP_REFERER=NO ;; --without-http_rewrite_module) HTTP_REWRITE=NO ;; --without-http_proxy_module) HTTP_PROXY=NO ;; --without-http_fastcgi_module) HTTP_FASTCGI=NO ;; --without-http_memcached_module) HTTP_MEMCACHED=NO ;; --without-http_limit_zone_module) HTTP_LIMIT_ZONE=NO ;; --without-http_limit_req_module) HTTP_LIMIT_REQ=NO ;; --without-http_empty_gif_module) HTTP_EMPTY_GIF=NO ;; --without-http_browser_module) HTTP_BROWSER=NO ;; --without-http_upstream_ip_hash_module) HTTP_UPSTREAM_IP_HASH=NO ;;

--with-http_perl_module) HTTP_PERL=YES ;; --with-perl_modules_path=*) NGX_PERL_MODULES="$value" ;; --with-perl=*) NGX_PERL="$value" ;;

# STUB --with-http_stub_status_module) HTTP_STUB_STATUS=YES ;;

--with-mail) MAIL=YES ;; --with-mail_ssl_module) MAIL_SSL=YES ;; # STUB --with-imap) MAIL=YES ;; --with-imap_ssl_module) MAIL_SSL=YES ;; --without-mail_pop3_module) MAIL_POP3=NO ;; --without-mail_imap_module) MAIL_IMAP=NO ;; --without-mail_smtp_module) MAIL_SMTP=NO ;;

--with-google_perftools_module) NGX_GOOGLE_PERFTOOLS=YES ;; --with-cpp_test_module) NGX_CPP_TEST=YES ;;

--add-module=*) NGX_ADDONS="$NGX_ADDONS $value" ;;

--with-cc=*) CC="$value" ;; --with-cpp=*) CPP="$value" ;; --with-cc-opt=*) NGX_CC_OPT="$value" ;; --with-ld-opt=*) NGX_LD_OPT="$value" ;; --with-cpu-opt=*) CPU="$value" ;; --with-debug) NGX_DEBUG=YES ;;

--without-pcre) USE_PCRE=DISABLED ;; --with-pcre) USE_PCRE=YES ;; --with-pcre=*) PCRE="$value" ;; --with-pcre-opt=*) PCRE_OPT="$value" ;;

--with-openssl=*) OPENSSL="$value" ;; --with-openssl-opt=*) OPENSSL_OPT="$value" ;;

--with-md5=*) MD5="$value" ;; --with-md5-opt=*) MD5_OPT="$value" ;; --with-md5-asm) MD5_ASM=YES ;;

--with-sha1=*) SHA1="$value" ;; --with-sha1-opt=*) SHA1_OPT="$value" ;; --with-sha1-asm) SHA1_ASM=YES ;;

--with-zlib=*) ZLIB="$value" ;; --with-zlib-opt=*) ZLIB_OPT="$value" ;; --with-zlib-asm=*) ZLIB_ASM="$value" ;;

--test-build-devpoll) NGX_TEST_BUILD_DEVPOLL=YES ;; --test-build-eventport) NGX_TEST_BUILD_EVENTPORT=YES ;; --test-build-epoll) NGX_TEST_BUILD_EPOLL=YES ;; --test-build-rtsig) NGX_TEST_BUILD_RTSIG=YES ;; --test-build-solaris-sendfilev) NGX_TEST_BUILD_SOLARIS_SENDFILEV=YES ;;

*) echo "$0: error: invalid option \"$option\""#如果参数不满足上面所列的要求,则直接报错,并结束程序 exit 1 ;; esacdone

NGX_CONFIGURE="$opt"#$opt是一个所有参数组成的字符串,以空格分隔

if [ $help = yes ]; then#如果是help则返回帮助文档,用于告诉用户该怎么配置参数

cat << END#用的是here文档

--help this message

--prefix=PATH set the installation prefix --sbin-path=PATH set path to the nginx binary file --conf-path=PATH set path to the nginx.conf file --error-log-path=PATH set path to the error log --pid-path=PATH set path to nginx.pid file --lock-path=PATH set path to nginx.lock file

--user=USER set non-privilege user for the worker processes --group=GROUP set non-privilege group for the worker processes

--builddir=DIR set the build directory

--with-rtsig_module enable rtsig module --with-select_module enable select module --without-select_module disable select module --with-poll_module enable poll module --without-poll_module disable poll module

--with-ipv6 enable ipv6 support

--with-http_ssl_module enable ngx_http_ssl_module --with-http_realip_module enable ngx_http_realip_module --with-http_addition_module enable ngx_http_addition_module --with-http_xslt_module enable ngx_http_xslt_module --with-http_image_filter_module enable ngx_http_image_filter_module --with-http_geoip_module enable ngx_http_geoip_module --with-http_sub_module enable ngx_http_sub_module --with-http_dav_module enable ngx_http_dav_module --with-http_flv_module enable ngx_http_flv_module --with-http_gzip_static_module enable ngx_http_gzip_static_module --with-http_random_index_module enable ngx_http_random_index_module --with-http_secure_link_module enable ngx_http_secure_link_module --with-http_stub_status_module enable ngx_http_stub_status_module

--without-http_charset_module disable ngx_http_charset_module --without-http_gzip_module disable ngx_http_gzip_module --without-http_ssi_module disable ngx_http_ssi_module --without-http_userid_module disable ngx_http_userid_module --without-http_access_module disable ngx_http_access_module --without-http_auth_basic_module disable ngx_http_auth_basic_module --without-http_autoindex_module disable ngx_http_autoindex_module --without-http_geo_module disable ngx_http_geo_module --without-http_map_module disable ngx_http_map_module --without-http_referer_module disable ngx_http_referer_module --without-http_rewrite_module disable ngx_http_rewrite_module --without-http_proxy_module disable ngx_http_proxy_module --without-http_fastcgi_module disable ngx_http_fastcgi_module --without-http_memcached_module disable ngx_http_memcached_module --without-http_limit_zone_module disable ngx_http_limit_zone_module --without-http_limit_req_module disable ngx_http_limit_req_module --without-http_empty_gif_module disable ngx_http_empty_gif_module --without-http_browser_module disable ngx_http_browser_module --without-http_upstream_ip_hash_module disable ngx_http_upstream_ip_hash_module

--with-http_perl_module enable ngx_http_perl_module --with-perl_modules_path=PATH set path to the perl modules --with-perl=PATH set path to the perl binary

--http-log-path=PATH set path to the http access log --http-client-body-temp-path=PATH set path to the http client request body temporary files --http-proxy-temp-path=PATH set path to the http proxy temporary files --http-fastcgi-temp-path=PATH set path to the http fastcgi temporary files

--without-http disable HTTP server --without-http-cache disable HTTP cache

--with-mail enable POP3/IMAP4/SMTP proxy module --with-mail_ssl_module enable ngx_mail_ssl_module --without-mail_pop3_module disable ngx_mail_pop3_module --without-mail_imap_module disable ngx_mail_imap_module --without-mail_smtp_module disable ngx_mail_smtp_module

--with-google_perftools_module enable ngx_google_perftools_module --with-cpp_test_module enable ngx_cpp_test_module

--add-module=PATH enable an external module

--with-cc=PATH set path to C compiler --with-cpp=PATH set path to C preprocessor --with-cc-opt=OPTIONS set additional options for C compiler --with-ld-opt=OPTIONS set additional options for linker --with-cpu-opt=CPU build for specified CPU, the valid values: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, sparc32, sparc64, ppc64

--without-pcre disable PCRE library usage --with-pcre force PCRE library usage --with-pcre=DIR set path to PCRE library sources --with-pcre-opt=OPTIONS set additional options for PCRE building

--with-md5=DIR set path to md5 library sources --with-md5-opt=OPTIONS set additional options for md5 building --with-md5-asm use md5 assembler sources

--with-sha1=DIR set path to sha1 library sources --with-sha1-opt=OPTIONS set additional options for sha1 building --with-sha1-asm use sha1 assembler sources

--with-zlib=DIR set path to zlib library sources --with-zlib-opt=OPTIONS set additional options for zlib building --with-zlib-asm=CPU use zlib assembler sources optimized for specified CPU, the valid values: pentium, pentiumpro

--with-openssl=DIR set path to OpenSSL library sources --with-openssl-opt=OPTIONS set additional options for OpenSSL building

--with-debug enable the debugging logging

END

exit 1fi

if [ $HTTP = NO ]; then#如果关掉http模块,则所有与http相关的模块就全部关闭 HTTP_CHARSET=NO HTTP_GZIP=NO HTTP_SSI=NO HTTP_USERID=NO HTTP_ACCESS=NO HTTP_STATUS=NO HTTP_REWRITE=NO HTTP_PROXY=NO HTTP_FASTCGI=NOfi

if [ ".$NGX_PLATFORM" = ".win32" ]; then#是否是windows系统环境 NGX_WINE=$WINEfi

NGX_CONF_PATH=${NGX_CONF_PATH:-conf/nginx.conf}#对变量赋值并匹配默认值 nginx的配置文件,如果NGX_CONF_PATH为空,则使用:号后面的默认值NGX_CONF_PREFIX=`dirname $NGX_CONF_PATH`NGX_PID_PATH=${NGX_PID_PATH:-logs/nginx.pid}NGX_LOCK_PATH=${NGX_LOCK_PATH:-logs/nginx.lock}

if [ ".$NGX_ERROR_LOG_PATH" = ".stderr" ]; then NGX_ERROR_LOG_PATH=else NGX_ERROR_LOG_PATH=${NGX_ERROR_LOG_PATH:-logs/error.log}fi

NGX_HTTP_LOG_PATH=${NGX_HTTP_LOG_PATH:-logs/access.log}#日志位置NGX_HTTP_CLIENT_TEMP_PATH=${NGX_HTTP_CLIENT_TEMP_PATH:-client_body_temp}NGX_HTTP_PROXY_TEMP_PATH=${NGX_HTTP_PROXY_TEMP_PATH:-proxy_temp}NGX_HTTP_FASTCGI_TEMP_PATH=${NGX_HTTP_FASTCGI_TEMP_PATH:-fastcgi_temp}

case ".$NGX_PERL_MODULES" in ./*) ;;

.) ;;

*) NGX_PERL_MODULES=$NGX_PREFIX/$NGX_PERL_MODULES ;;esac