


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 << END … END exit 1 fi </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.

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

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

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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.

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

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.

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 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 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 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# 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
