Anatomy of Nginx automatic scripts (1) parsing configuration option script auto/options

Source: Internet
Author: User
: This article mainly introduces anatomy of Nginx automatic scripts (1) parsing configuration option script autooptions. For more information about PHP tutorials, see. Anatomy of Nginx automatic scripts (1) parsing configuration option script auto/options

  • Author: Poechant
  • Blog: blog.CSDN.net/Poechant
  • Email: zhongchao. ustc # gmail.com (#-> @)
  • Date: March 4th, 2012
  • Copyright? Liu Da-Poechant
  • Install NginxBefore (that is, running makeBefore the script), the first step is to prepare the installation configuration, including environment check and file generation. These tasks are completed by automatic scripts. Like most software, NginxThe entry to the automatic script, also named configure.

    Besides configure, Other automatic scripts are autoDirectory. Through analysis configureScript source code, we can see, configureFirst Run autoThe automatic scripts in the directory are as follows:

    . auto/options. auto/init. auto/sources
    Run auto/optionsScript to set the configuration options. The following will be analyzed gradually auto/optionsHow the script works.

    1 read configureConfiguration parameters

    First declare N multi-variables, and then the main part starts from this section:

    opt=for option    do    ...done
    This section is actually processing and running ./configureParameter options, forEach cycle corresponds to a parameter option. Note: forThere is a global optVariable. The first statement in the body of this loop is the most important. it is:

    opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\""`
    After the statement is run cyclically, optIs a list of parameters separated by spaces. Next in the loop body is case-esacTo obtain the parameter value, as follows:

    case "$option" in    -*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;       *) value="" ;;esac
    The meaning is valueIf the option value is not the same -*=* valueThe value is "". Next case-esacThe statement is used to match the parameter type.

        case "$option" in        --help)                          help=yes                   ;;        --prefix=)                       NGX_PREFIX="!"             ;;        --prefix=*)                      NGX_PREFIX="$value"        ;;        --sbin-path=*)                   NGX_SBIN_PATH="$value"     ;;        --conf-path=*)                   NGX_C     ;;        ...    esac
    Assign values to configuration variables in each matching Branch statement. These variables are auto/optionsThe default value is assigned at the beginning of the script, and the configuration variables of those modules are assigned YESIs enabled by default. NOIs disabled by default. But whether they are enabled or not depends on auto/optionsIn case-esacStatement. Some installation-related option variables are also assigned here, for example:

  • prefixParameter value is assignedNGX_PREFIX
  • sbin-pathParameter value is assignedNGX_SBIN_PATH
  • conf-pathParameter value is assignedNGX_CONF_PATH
  • error-log-pathParameter value is assignedNGX_ERROR_LOG_PATH
  • pid-pathParameter value is assignedNGX_PID_PATH
  • lock-pathParameter value is assignedNGX_LOCK_PATH
  • If optionIt does not match the predefined matches, that is, the user uses configureIf the parameter carried during the script is incorrect auto/optionsMatch the statement:

    *)    echo "$0: error: invalid option \"$option\""    exit 1
    In this way, the user parameter is prompted and the script is exited. After multiple cycles, for-do-doneEnd.

    2 settings NGX_CONFIGUREVariable

    All processed optionAfter, optAs we mentioned above, it becomes the configuration item value separated by spaces and is assigned NGX_CONFIGUREVariable:

    NGX_C
    3 show or not configureHelp information

    Let's look at the following sentence:

    if [ $help = yes ]; thencat << END    …END    exit 1fi
    By default $helpThe variable value is no. If configureThe helpParameter, then $helpThe parameter is yesWill run catCommand to display the help information of a large segment, and then exit.

    4. disable HTTP?

    By default HTTPSome basic functions are enabled. if you specify --without-httpParameter, then the variable HTTPWill be assigned NO, The following code if-fiThe statement in is executed:

    if [ $HTTP = NO ]; then    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
    5. specify whether to run on Windows

    If you explicitly specify --crossbuildParameter, then the variable NGX_PLATFORMWill be assigned to the current for-do-doneIn the Loop "$value"Value, that is --crossbuildThe parameter value is generally considered in WindowsIt is used only when the platform is used. See the following statement:

    if [ ".$NGX_PLATFORM" = ".win32" ]; then    NGX_WINE=$WINEfi
    If you specify --crossbuild=win32, Then NGX_WINEIt will be assigned a value.

    6. Nginx configuration file path

    Loading configureIf no parameter is specified --conf-pathParameter, then $NGX_CONF_PATHIf the variable has no value, the following statement will NGX_CONF_PATHGrant conf/nginx.conf. However, I was wondering if you can find auto/optionsSpecify the start point as other parameters. NGX_CONF_PATH.

    NGX_C/nginx.conf}
    Then obtain the directory where the configuration file is located:

    NGX_C $NGX_CONF_PATH`
    If you specify a parameter --conf-path=/home/michael/nginx/conf/nginx.conf, Then NGX_CONF_PREFIXThe value is /home/michael/nginx/conf.

    7. Nginx process ID file and lock file path

    The following is the same method of initialization NGX_PID_PATHAnd NGX_LOCK_PATH, Corresponding configureParameters --pid-pathAnd --lock-pathThe default values are logs/nginx.pidAnd logs/nginx.lock.

    NGX_PID_PATH=${NGX_PID_PATH:-logs/nginx.pid}NGX_LOCK_PATH=${NGX_LOCK_PATH:-logs/nginx.lock}
    8. path of the error log file

    If the parameter is specified --error-log-pathThen NGX_ERROR_LOG_PATHThe variable value is specified. according to the following statement, if stderrThen NGX_ERROR_LOG_PATHIf it is changed to Null, no error log file is required. If it is not a standard output and its value is null, it is set to the default value. logs/error.log.

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

    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}NGX_HTTP_UWSGI_TEMP_PATH=${NGX_HTTP_UWSGI_TEMP_PATH:-uwsgi_temp}NGX_HTTP_SCGI_TEMP_PATH=${NGX_HTTP_SCGI_TEMP_PATH:-scgi_temp}
    10 Perl module

    If --with-perl_modules_pathParameter, then NGX_PERL_MODULESVariables are set. If the specified value is an absolute path or is not specified (null), it is treated as a relative path and set $NGX_PREFIX/$NGX_PERL_MODULES.

    case ".$NGX_PERL_MODULES" in    ./*)    ;;    .)    ;;    *)        NGX_PERL_MODULES=$NGX_PREFIX/$NGX_PERL_MODULES    ;;esac
    11 Summary

    Run auto/optionsScript. all configuration items have been correctly parsed and loaded into the corresponding configuration variables.

    -

    For more information, see "Liu Da's CSDN blog": blog.csdn.net/Poechant

    -

    The above introduces the anatomy of Nginx automatic scripts (1) parsing configuration option script auto/options, including the content, hope to be helpful to friends who are interested in PHP tutorials.

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.