: 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
Nginx
Before (that is, running
make
Before 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,
Nginx
The entry to the automatic script, also named
configure
.
Besides
configure
, Other automatic scripts are
auto
Directory. Through analysis
configure
Script source code, we can see,
configure
First Run
auto
The automatic scripts in the directory are as follows:
. auto/options. auto/init. auto/sources
Run
auto/options
Script to set the configuration options. The following will be analyzed gradually
auto/options
How the script works.
1 read
configure
Configuration 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
./configure
Parameter options,
for
Each cycle corresponds to a parameter option. Note:
for
There is a global
opt
Variable. 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,
opt
Is a list of parameters separated by spaces. Next in the loop body is
case-esac
To obtain the parameter value, as follows:
case "$option" in -*=*) value=`echo "$option" | sed -e 's/[-_a-zA-Z0-9]*=//'` ;; *) value="" ;;esac
The meaning is
value
If the option value is not the same
-*=*
value
The value is
""
. Next
case-esac
The 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/options
The default value is assigned at the beginning of the script, and the configuration variables of those modules are assigned
YES
Is enabled by default.
NO
Is disabled by default. But whether they are enabled or not depends on
auto/options
In
case-esac
Statement. Some installation-related option variables are also assigned here, for example:
prefix
Parameter value is assignedNGX_PREFIX
sbin-path
Parameter value is assignedNGX_SBIN_PATH
conf-path
Parameter value is assignedNGX_CONF_PATH
error-log-path
Parameter value is assignedNGX_ERROR_LOG_PATH
pid-path
Parameter value is assignedNGX_PID_PATH
lock-path
Parameter value is assignedNGX_LOCK_PATH
If
option
It does not match the predefined matches, that is, the user uses
configure
If the parameter carried during the script is incorrect
auto/options
Match 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-done
End.
2 settings
NGX_CONFIGURE
Variable
All processed
option
After,
opt
As we mentioned above, it becomes the configuration item value separated by spaces and is assigned
NGX_CONFIGURE
Variable:
NGX_C
3 show or not
configure
Help information
Let's look at the following sentence:
if [ $help = yes ]; thencat << END …END exit 1fi
By default
$help
The variable value is
no
. If
configure
The
help
Parameter, then
$help
The parameter is
yes
Will run
cat
Command to display the help information of a large segment, and then exit.
4. disable HTTP?
By default
HTTP
Some basic functions are enabled. if you specify
--without-http
Parameter, then the variable
HTTP
Will be assigned
NO
, The following code
if-fi
The 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
--crossbuild
Parameter, then the variable
NGX_PLATFORM
Will be assigned to the current
for-do-done
In the Loop
"$value"
Value, that is
--crossbuild
The parameter value is generally considered in
Windows
It 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_WINE
It will be assigned a value.
6. Nginx configuration file path
Loading
configure
If no parameter is specified
--conf-path
Parameter, then
$NGX_CONF_PATH
If the variable has no value, the following statement will
NGX_CONF_PATH
Grant
conf/nginx.conf
. However, I was wondering if you can find
auto/options
Specify 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_PREFIX
The 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_PATH
And
NGX_LOCK_PATH
, Corresponding
configure
Parameters
--pid-path
And
--lock-path
The default values are
logs/nginx.pid
And
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-path
Then
NGX_ERROR_LOG_PATH
The variable value is specified. according to the following statement, if
stderr
Then
NGX_ERROR_LOG_PATH
If 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_path
Parameter, then
NGX_PERL_MODULES
Variables 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/options
Script. 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.