


Anatomy of Nginx automatic script (1) Parsing configuration option script auto/options
Nginx
之前(即运行make
脚本之前),首先是进行安装的配置准备,包括环境检查及生成文件。这些工作是由自动脚本完成的。和绝大多数软件一样,Nginx
的自动脚本的入口,同样是名为configure
的文件。configure
,其他的自动脚本都在auto
目录下。通过分析configure
脚本源码,我们可以看到,configure
首先运行了auto
目录下的几个自动脚本,如下:<code>. auto/options . auto/init . auto/sources </code>
auto/options
脚本,来设定配置选项。下面将逐步分析auto/options
脚本是如何工作的。configure
配置参数<code>opt= for option do ... done </code>
./configure
的时候携带的参数选项,for
循环每次对应一个参数选项
option。要注意for
循环体上面有一个全局的opt
变量。这个循环体内的第一个语句是最重要是,它是:<code>opt="$opt `echo $option | sed -e \"s/\(--[^=]*=\)\(.* .*\)/\1'\2'/\"`" </code>
opt
的值就是一个由空格来分隔的参数列表。然后在循环体中接下来是一个case-esac
,用来得到参数值,如下:<code>case "$option" in -*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;; *) value="" ;; esac </code>
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>
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>
for-do-done
就结束。NGX_CONFIGURE
变量option
后,opt
就如我们上面提到的,成为由空格分割的配置项值,并被赋给NGX_CONFIGURE
变量:<code>NGX_C </code>
configure
的帮助信息<code>if [ $help = yes ]; then cat </code>
$help
变量值在初始化时就为no
。如果configure
选项中指定了help
参数,则$help
参数为yes
,则会运行cat
命令,显示大段的帮助信息,然后退出。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>
--crossbuild
参数,则变量NGX_PLATFORM
会被赋予当前for-do-done
循环中的"$value"
值,也就是--crossbuild
的参数值,一般在考虑在Windows
平台使用时才会用到,看下面的语句:<code>if [ ".$NGX_PLATFORM" = ".win32" ]; then NGX_WINE=$WINE fi </code>
--crossbuild=win32
,则NGX_WINE
就会被赋值了。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>
<code>NGX_C $NGX_CONF_PATH` </code>
--conf-path=/home/michael/nginx/conf/nginx.conf
,则NGX_CONF_PREFIX
的值就是/home/michael/nginx/conf
。NGX_PID_PATH
和NGX_LOCK_PATH
,分别对应configure
参数--pid-path
和--lock-path
,其缺省值分别为logs/nginx.pid
和logs/nginx.lock
。<code>NGX_PID_PATH=${NGX_PID_PATH:-logs/nginx.pid} NGX_LOCK_PATH=${NGX_LOCK_PATH:-logs/nginx.lock} </code>
--error-log-path
则NGX_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>
<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>
--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>
auto/options
脚本,所有的配置项已经被正确解析并加载到相应的配置变量中了。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.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.