Most developers who use MAC install all kinds of software through brew command, such as PHP, python, nodejs, and nginx.
By default, nginx is installed in the
brew link nginxAdd soft connection to
/usr/local/bin/nginx, although it fully meets the requirements of development and conforms to the management of mac software, but it is not convenient to transplant (for example, if you want to deploy an application package to a user who does not understand the development with one click, the students who do the privatization deployment should be familiar with this).
Compiling nginx program from source is much more flexible than installing precompiled installation package. You can add specific modules (from the official or third-party of nginx, such as fastdfs nginx module, which provides fastdfs with the ability of HTTP access to files). Of course, you can compile the source code to pull the latest branches of bug fixes and new features.
- PCRE — supports regular expressions. It is the core of nginx and the required dependency Library of rewrite module.
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.bz2 tar zxf pcre-8.43.tar.bz2
- Zlib — supports header compression. Required by the gzip module of nginx.
wget http://zlib.net/zlib-1.2.11.tar.gz tar zxf zlib-1.2.11.tar.gz
- OpenSSL — supports HTTPS protocol. It is required by the SSL module and other modules of nginx.
wget http://www.openssl.org/source/openssl-1.1.1c.tar.gz tar zxf openssl-1.1.1c.tar.gz
wget https://nginx.org/download/nginx-1.17.4.tar.gz tar zxf nginx-1.17.4.tar.gz cd nginx-1.17.4
Configure build options
Nginx compilation configuration options are selected by
./configureSet various parameters, including source and configuration file paths, compilation options, link handling methods, and module lists. adopt
MakefileCompile code and install nginx.
./configure \ --user=nginx \ --group=nginx \ --prefix=./nginx \ --sbin-path=nginx \ --conf-path=nginx.conf \ --pid-path=nginx.pid \ --with-http_ssl_module \ --with-pcre=../pcre-8.43 \ --with-zlib=../zlib-1.2.11 \ --with-openssl=../openssl-1.1.1c
--prefix=path-Define a directory that will hold the server files. The same directory will be used in all relative paths set by configure (except for the path to the library source) and in the nginx.conf configuration file. It defaults to
--sbin-path=path-Set the name of the nginx executable. The name is used only during installation. By default, the file is named
--conf-path=path-Set the name of the nginx.conf configuration file. If necessary, by using the
-cThe configuration file of nginx is specified in the file. Nginx can always be started with a different configuration file. By default, the file name is
--pid-path=path-Set the name of the nginx.pid file that will store the process ID of the main process. After installation, you can always change the file name in the nginx.conf configuration file using the PID instruction. By default, the file name is
--error-log-path=path-Set the name of the main error, warning, and diagnostic file. After the installation is complete, you can always change the filename in the nginx.conf configuration file using the error log instruction. By default, the file name is
--http-log-path=path-Sets the name of the primary request log file for the HTTP server. After the installation is complete, you can always change the file name in the nginx.conf configuration file using the access? Log command. By default, the file is named
--build=name-Set an optional nginx build name.
--user=name-Sets the name of the unprivileged user whose credentials will be used by the worker process. After installation, you can use the
userThe directive always changes the name in the nginx.conf configuration file. The default user name is
--group=name-Sets the name of the group whose credentials the worker process will use. After installation, you can use the
userThe directive always changes the name in the nginx.conf configuration file. By default, the group name is set to the name of the unprivileged user.
-Enable or disable build allow nginx to useselect()
Method. If the platform may not support a more appropriate approach (for examplekqueue
or/Dev / poll ‘), the module will be built automatically.
--with-poll_module --without-poll_module-Enable or disable the build to allow nginx to use this
poll()Method. If the platform does not seem to support a more appropriate approach (for example
/dev/poll）, the module is built automatically.
--without-http_gzip_module-Disable building modules that compress HTTP server responses. The zlib library is required to build and run this module.
--without-http_rewrite_module-Disable building a module that allows the HTTP server to redirect requests and change the request URI. The PCRE library needs to build and run the module.
--without-http_proxy_module-Disable building the HTTP server proxy module.
--with-http_ssl_module-You can build a module that adds HTTPS protocol support to the HTTP server. The module is not generated by default. The OpenSSL library is required to build and run the module.
--with-pcre=path-Set the path to the PCRE library source. The release (version 4.4 – 8.41) needs to be downloaded and extracted from the PCRE website. The library is
ngx_http_rewrite_moduleModule is required to support regular expressions.
--with-pcre-jit-Build the PCRE library with “just in time compilation” support (1.1.12, PCRE JIT instruction).
--with-zlib=path-Set the path to the zlib library source. The library distribution (version 1.1.3 – 1.2.11) needs to be downloaded from the zlib site and uncompressed. The library is
ngx_http_gzip_moduleRequired by the module.
--with-cc-opt=parameters-Set the additional parameters that will be added to the cflags variable. When using the system PCRE Library under FreeBSD, – with CC opt = “- I / usr / local / include” should be specified. If select() needs to increase the number of supported files, you can also specify the following here: – with CC opt = “- D fd_setsize = 2048”.
--with-ld-opt=parameters-Set additional parameters that will be used during the link. When using the system PCRE Library under FreeBSD, – with LD opt = “- L / usr / local / lib” should be specified.
Compilation and installation
make && make install
Finally, the test related data output indicates that the compilation is successful:
test -d './nginx' || mkdir -p './nginx' test -d './nginx' \ || mkdir -p './nginx' test ! -f './nginx/nginx' \ || mv './nginx/nginx' \ './nginx/nginx.old' cp objs/nginx './nginx/nginx' test -d './nginx' \ || mkdir -p './nginx' cp conf/koi-win './nginx' cp conf/koi-utf './nginx' cp conf/win-utf './nginx' test -f './nginx/mime.types' \ || cp conf/mime.types './nginx' cp conf/mime.types './nginx/mime.types.default' test -f './nginx/fastcgi_params' \ || cp conf/fastcgi_params './nginx' cp conf/fastcgi_params \ './nginx/fastcgi_params.default' test -f './nginx/fastcgi.conf' \ || cp conf/fastcgi.conf './nginx' cp conf/fastcgi.conf './nginx/fastcgi.conf.default' test -f './nginx/uwsgi_params' \ || cp conf/uwsgi_params './nginx' cp conf/uwsgi_params \ './nginx/uwsgi_params.default' test -f './nginx/scgi_params' \ || cp conf/scgi_params './nginx' cp conf/scgi_params \ './nginx/scgi_params.default' test -f './nginx/nginx.conf' \ || cp conf/nginx.conf './nginx/nginx.conf' cp conf/nginx.conf './nginx/nginx.conf.default' test -d './nginx' \ || mkdir -p './nginx' test -d './nginx/logs' \ || mkdir -p './nginx/logs' test -d './nginx/html' \ || cp -R html './nginx' test -d './nginx/logs' \ || mkdir -p './nginx/logs'
Errors or precautions
- Missing PCRE error in make phase
make: * [/usr/local/Cellar/pcre/8.43/lib//Makefile] Error 127
For the higher version of nginx, you need to use the original file path of PCRE
--with-pcre=PATHSpecify the source path of PCRE.
--prefixSpecifies the prefix for the location of the entire compiled output file
If other configuration items are not specified or are relative paths, add
prefixConfiguration path for.
Installing NGINX Open Source
Building nginx from Sources
This article was first published in the blog of “empty mind like Valley”. Please sign your name before reprinting, and indicate the source of reprinting.
Those who are good in the ancient times are subtle and profound. The only thing I can’t know is my strength
Henan is like a river in winter. It’s as if it’s afraid of its neighbors. It’s as if it’s a guest. It’s as slack as ice. It’s as simple as a town. It’s as wide as a valley. It’s as muddy as a cloud.
Which can be turbid and quiet? Who can live with ease?
I want to keep this way. The only thing I can do is not gain, so I can open up and make a new one.
Please pay attention to my WeChat official account.Rain is like playing the piano，Thanks♪(･ω･)ﾉ