Home Backend Development PHP Tutorial Anatomy of Nginx automatic script (1) Parsing configuration option script auto/options

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

Aug 08, 2016 am 09:19 AM
http path temp

解剖 Nginx ·自动脚本篇(1)解析配置选项脚本 auto/options
  • Author: Poechant
  • Blog: blog.CSDN.net/Poechant
  • Email: zhongchao.ustc#gmail.com (#->@)
  • Date: March 4th, 2012
  • Copyright ? 柳大·Poechant
  • 在安装Nginx之前(即运行make脚本之前),首先是进行安装的配置准备,包括环境检查及生成文件。这些工作是由自动脚本完成的。和绝大多数软件一样,Nginx的自动脚本的入口,同样是名为configure的文件。除了configure,其他的自动脚本都在auto目录下。通过分析configure脚本源码,我们可以看到,configure首先运行了auto目录下的几个自动脚本,如下:
    <code>. auto/options
    . auto/init
    . auto/sources
    </code>
    Copy after login
    其中通过运行auto/options脚本,来设定配置选项。下面将逐步分析auto/options脚本是如何工作的。1 读取configure配置参数开始先声明了 N 多变量,然后最主要的部分从这段开始:
    <code>opt=
    
    for option
        do
        ...
    done
    </code>
    Copy after login
    这段实际上是处理运行./configure的时候携带的参数选项,for循环每次对应一个参数选项 option。要注意for循环体上面有一个全局的opt变量。这个循环体内的第一个语句是最重要是,它是:
    <code>opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`"
    </code>
    Copy after login
    通过循环运行该语句后,opt的值就是一个由空格来分隔的参数列表。然后在循环体中接下来是一个case-esac,用来得到参数值,如下:
    <code>case "$option" in
        -*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;;
           *) value="" ;;
    esac
    </code>
    Copy after login
    其含义是将value赋值为参数选项值,如果选项值不与-*=*的模式匹配,则value值为""。接下来的case-esac语句用来匹配参数的类型。
    <code>    case "$option" in
            --help)                          help=yes                   ;;
            --prefix=)                       NGX_PREFIX="!"             ;;
            --prefix=*)                      NGX_PREFIX="$value"        ;;
            --sbin-path=*)                   NGX_SBIN_PATH="$value"     ;;
            --conf-path=*)                   NGX_C     ;;
            ...
        esac
    </code>
    Copy after login
    各匹配的分支语句中进行配置变量的赋值。这些变量在auto/options脚本的最开始处赋以默认值,其中那些模块配置变量被赋以YES的表示默认开启,赋以NO的表示默认关闭。但它们开启与否由这个auto/options中的case-esac语句来决定。还有一些是安装相关的选项变量也在这里被赋值,比如:
  • prefix参数值被赋予NGX_PREFIX
  • sbin-path参数值被赋予NGX_SBIN_PATH
  • conf-path参数值被赋予NGX_CONF_PATH
  • error-log-path参数值被赋予NGX_ERROR_LOG_PATH
  • pid-path参数值被赋予NGX_PID_PATH
  • lock-path参数值被赋予NGX_LOCK_PATH
  • 如果option并不符合预设的这些匹配,也就是用户使用configure脚本的时候携带的参数错误,则auto/options会匹配该语句:
    <code>*)
        echo "$0: error: invalid option \"$option\""
        exit 1
    </code>
    Copy after login
    从而提示用户参数错误,并使脚本退出运行。经过多次循环,for-do-done就结束。2 设定NGX_CONFIGURE变量处理完所有option后,opt就如我们上面提到的,成为由空格分割的配置项值,并被赋给NGX_CONFIGURE变量:
    <code>NGX_C
    </code>
    Copy after login
    3 是否显示configure的帮助信息再看下面这句:
    <code>if [ $help = yes ]; then
    cat << END
        …
    END
        exit 1
    fi
    </code>
    Copy after login
    默认情况下$help变量值在初始化时就为no。如果configure选项中指定了help参数,则$help参数为yes,则会运行cat命令,显示大段的帮助信息,然后退出。4 是否关闭 HTTP 功能默认情况下HTTP的一些基本功能是被开启的,如果用户指定了--without-http参数,则变量HTTP会被赋值为NO,则下面这段代码if-fi中的语句会被执行:
    <code>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=NO
    fi
    </code>
    Copy after login
    5 是否指定运行于 Windows 平台如果显式指定了--crossbuild参数,则变量NGX_PLATFORM会被赋予当前for-do-done循环中的"$value"值,也就是--crossbuild的参数值,一般在考虑在Windows平台使用时才会用到,看下面的语句:
    <code>if [ ".$NGX_PLATFORM" = ".win32" ]; then
        NGX_WINE=$WINE
    fi
    </code>
    Copy after login
    如果指定--crossbuild=win32,则NGX_WINE就会被赋值了。6 Nginx 配置文件路径在加载configure的参数时,如果没有指定了--conf-path参数,则$NGX_CONF_PATH变量是没有值的,则下面的语句会为NGX_CONF_PATH赋以conf/nginx.conf的缺省值。不过我在想老毛子 Igor Sysoev 同学完全可以在auto/options开始处和其他参数一样先指定NGX_CONF_PATH的默认值。
    <code>NGX_C/nginx.conf}
    </code>
    Copy after login
    然后获取配置文件所在目录的:
    <code>NGX_C $NGX_CONF_PATH`
    </code>
    Copy after login
    如果指定参数--conf-path=/home/michael/nginx/conf/nginx.conf,则NGX_CONF_PREFIX的值就是/home/michael/nginx/conf7 Nginx 进程 ID 文件和锁文件路径下面是同样的方式初始化NGX_PID_PATHNGX_LOCK_PATH,分别对应configure参数--pid-path--lock-path,其缺省值分别为logs/nginx.pidlogs/nginx.lock
    <code>NGX_PID_PATH=${NGX_PID_PATH:-logs/nginx.pid}
    NGX_LOCK_PATH=${NGX_LOCK_PATH:-logs/nginx.lock}
    </code>
    Copy after login
    8 错误日志文件路径如果指定了参数--error-log-pathNGX_ERROR_LOG_PATH变量的值会被指定,根据下面的语句,如果指定的是stderr则将NGX_ERROR_LOG_PATH修改为空,即不需要错误日志文件。如果不是标准输出,且其值为空,则设置为缺省值logs/error.log
    <code>if [ ".$NGX_ERROR_LOG_PATH" = ".stderr" ]; then
        NGX_ERROR_LOG_PATH=
    else
        NGX_ERROR_LOG_PATH=${NGX_ERROR_LOG_PATH:-logs/error.log}
    fi
    </code>
    Copy after login
    9 HTTP 相关各路径
    <code>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}
    </code>
    Copy after login
    10 Perl 模块如果指定了--with-perl_modules_path参数,则NGX_PERL_MODULES变量即被设定。如果指定的值为一个绝对路径或未指定(空),则当做相对路径来处理,设定为$NGX_PREFIX/$NGX_PERL_MODULES
    <code>case ".$NGX_PERL_MODULES" in
        ./*)
        ;;
    
        .)
        ;;
    
        *)
            NGX_PERL_MODULES=$NGX_PREFIX/$NGX_PERL_MODULES
        ;;
    esac
    </code>
    Copy after login
    11 小结通过运行auto/options脚本,所有的配置项已经被正确解析并加载到相应的配置变量中了。-转载请注明来自“柳大的CSDN博客”:blog.csdn.net/Poechant-

    The above has introduced the anatomy of Nginx automatic script (1) parsing the configuration options script auto/options, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    What does http status code 520 mean? What does http status code 520 mean? Oct 13, 2023 pm 03:11 PM

    HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

    Steps to set the PATH environment variable of the Linux system Steps to set the PATH environment variable of the Linux system Feb 18, 2024 pm 05:40 PM

    How to set the PATH environment variable in Linux systems In Linux systems, the PATH environment variable is used to specify the path where the system searches for executable files on the command line. Correctly setting the PATH environment variable allows us to execute system commands and custom commands at any location. This article will introduce how to set the PATH environment variable in a Linux system and provide detailed code examples. View the current PATH environment variable. Execute the following command in the terminal to view the current PATH environment variable: echo$P

    What is http status code 403? What is http status code 403? Oct 07, 2023 pm 02:04 PM

    HTTP status code 403 means that the server rejected the client's request. The solution to http status code 403 is: 1. Check the authentication credentials. If the server requires authentication, ensure that the correct credentials are provided; 2. Check the IP address restrictions. If the server has restricted the IP address, ensure that the client's IP address is restricted. Whitelisted or not blacklisted; 3. Check the file permission settings. If the 403 status code is related to the permission settings of the file or directory, ensure that the client has sufficient permissions to access these files or directories, etc.

    Teach you how to modify the temporary file location of Win7 Teach you how to modify the temporary file location of Win7 Jan 04, 2024 pm 11:25 PM

    The temp folder is our temporary file storage location. The system will save temporary files to this folder. If there are too many temporary files, especially when the temp folder is on the system disk, it is likely to affect the system running speed. We can solve the problem by changing the temp location. Let’s take a look below. Tutorial on changing the location of win7temp 1. First, right-click "Computer" and open "Properties" 2. Click "Advanced System Settings" on the left 3. Click "Environment Variables" below 4. Select "temp" and click "Edit" 5. Then change Just change the "Variable Value" to the path that needs to be changed.

    Understand common application scenarios of web page redirection and understand the HTTP 301 status code Understand common application scenarios of web page redirection and understand the HTTP 301 status code Feb 18, 2024 pm 08:41 PM

    Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

    How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS How to use Nginx Proxy Manager to implement automatic jump from HTTP to HTTPS Sep 26, 2023 am 11:19 AM

    How to use NginxProxyManager to implement automatic jump from HTTP to HTTPS. With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt data transmission to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and NginxProxy

    Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files Sep 12, 2023 pm 01:15 PM

    Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files With the development of the Internet, the file download function has become one of the basic needs of many websites and applications. For scenarios where multiple files need to be downloaded at the same time, the traditional synchronous download method is often inefficient and time-consuming. For this reason, using PHP to download multiple files asynchronously over HTTP has become an increasingly common solution. This article will analyze in detail how to use PHP asynchronous HTTP through an actual development case.

    Common network communication and security problems and solutions in C# Common network communication and security problems and solutions in C# Oct 09, 2023 pm 09:21 PM

    Common network communication and security problems and solutions in C# In today's Internet era, network communication has become an indispensable part of software development. In C#, we usually encounter some network communication problems, such as data transmission security, network connection stability, etc. This article will discuss in detail common network communication and security issues in C# and provide corresponding solutions and code examples. 1. Network communication problems Network connection interruption: During the network communication process, the network connection may be interrupted, which may cause

    See all articles