Home >Operation and Maintenance >Nginx >How to install nginx
#nginx can be installed using the default packages of each platform. This article introduces the use of source code compilation and installation, including specific compilation parameter information. Before the official start, the compilation environment gcc g development library and the like need to be installed in advance. By default, you have already installed it. ububtu platform compilation environment can use the following instructions
2 |
apt -get install build- essential apt-get install libtool |
centos platform compilation environment uses the following instructions
to install make:
##1 | yum -y install gcc automake autoconf libtool make |
##1 | yum install gcc gcc-c |
1 |
cd /usr/local/src |
2. Install the PCRE library
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ Download the latest PCRE source code package, use the following command to download, compile and install the PCRE package:
##12 34567 |
cd /usr/local/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/ pcre/pcre-8.37.tar.gz tar -zxvf pcre-8.37.tar.gz cd pcre-8.34 ./configure make make install |
3. Install zlib library
http://zlib.net/zlib-1.2.8.tar.gz Download the latest zlib source package, Use the following commands to download, compile and install the zlib package:
#12345678 |
cd /usr/local/ src wget http://zlib.net/zlib-1.2. 8.tar.gz tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure make make install |
4. Install ssl (some vps do not have ssl installed by default)
1 2 3 |
##cd /usr/local/src wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz tar -zxvf openssl-1.0.1t.tar.gz |
5. Install nginx
Nginx generally has two versions, namely the stable version and the development version. You can choose according to your purpose. Choose one of these two versions. Here are the detailed steps to install Nginx to the /usr/local/nginx directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
cd /usr/local/src ##wget http: //nginx.org/download/nginx-1.4.2.tar.gz tar -zxvf nginx-1.4.2.tar.gz cd nginx-1.4.2
./configure --sbin-path=/usr/local/nginx/nginx \ --conf-path=/usr/local/nginx/nginx.conf \ --pid-path=/usr/local/nginx/nginx.pid \ --with-http_ssl_module \ --with-pcre=/opt/app/openet/oetal1/chenhe/pcre-8.37 \ --with-zlib=/opt/app/openet/oetal1/chenhe/zlib-1.2.8 \ --with-openssl=/opt/app/openet/oetal1/chenhe/openssl-1.0.1t
make make install |
--with-pcre=/usr/src/pcre-8.34 refers to the source code path of pcre-8.34.
--with-zlib=/usr/src/zlib-1.2.7 refers to the source code path of zlib-1.2.7.
After successful installation, the /usr/local/nginx directory is as follows
##123456 |
fastcgi .conf koi-win ##conf.default fastcgi.conf.default logs scgi_params fastcgi_params mime.types scgi_params.default fastcgi_params.default mime.types.default uwsgi_params html nginx uwsgi_params.default koi-utf nginx.conf win-utf |
6. Start
Make sure that port 80 of the system is not occupied by other programs, run the /usr/local/nginx/nginx command to start Nginx,
1 |
##netstat - ano|grep 80 |
1 |
##sudo /usr/local/nginx/nginx |
##12345 |
libtool: compile: unrecognized option `-DHAVE_CONFIG_H' libtool: compile: Try `libtool --help' for more information. make[1]: *** [pcrecpp.lo] Error 1 make[1]: Leaving directory `/usr/local/src/pcre-8.34' make: *** [all] Error 2 |
Solution: Install g, don’t forget to reconfigure
1 2 3 4 5 |
apt-get install g apt-get install build-essential make clean ./configure make |
1.2 make出错
1 2 3 4 5 |
make: *** No rule to make target `build', needed by `default'. Stop. ./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using --with-openssl=path> option. |
Follow the installation method in step 4 or
ubuntu
1 2 |
##apt-get install openssl apt-get install libssl-dev |
1 |
yum -y install openssl openssl-devel |
2.nginx compilation options
make is used for compilation. It reads instructions from the Makefile and then compiles.
make install is used for installation. It also reads instructions from the Makefile and installs it to the specified location.
The configure command is used to detect the target characteristics of your installation platform. It defines all aspects of the system, including the connection processing methods that nginx is allowed to use. For example, it will detect whether you have CC or GCC. It does not require CC or GCC. It is a shell script. When execution ends, it will Create a Makefile. The configure command of nginx supports the following parameters:
##--prefix=<code>path<em></em>
Define a directory to store on the server file, which is the installation directory of nginx. By default, /usr/local/nginx is used.
--sbin-path=<code>path<em></em>
Set the path to the nginx executable file, default For <code>prefix<em></em>/sbin/nginx
.
--conf-path=<code>path<em></em>
Set the path to the nginx.conf configuration file. nginx allows starting with different configuration files through the -c option on the command line. The default is <code>prefix<em></em>/conf/nginx.conf
.
--pid-path=<code>path<em> Set the nginx.pid file to store the process ID of the main process. After the installation is complete, the file name can be changed at any time by using the PID directive in the nginx.conf configuration file. By default, the file name is </em>
<code>prefix<em></em>/logs/nginx.pid
.
--error-log-path=<code>path<em></em>
Set the name of the main error, warning, and diagnostic files. After the installation is complete, you can change the file name at any time by using the error_log directive in the nginx.conf configuration file. By default, the file name is <code>prefix<em></em>/logs/error.log
.
-- http-log-path=<code>path<em></em>
Set the name of the log file of the HTTP server for the main request. After the installation is complete, you can change the file name at any time by using the access_log directive in the nginx.conf configuration file. By default, the file name is <code>prefix<em></em>/logs/access.log
.
-- user=<code>name<em></em>
Set the user of the nginx worker process. After installation is complete, the name can be changed at any time in the nginx.conf configuration file using the user directive. The default username is nobody.
--group=<code>name<em></em>
Set the user group of the nginx worker process. After installation is complete, the name can be changed at any time in the nginx.conf configuration file using the user directive. The default is unprivileged user.
--with-select_module
--without-select_module Enables or disables building a module to allow the server to use the select() method. This module will be built automatically if the platform does not support kqueue, epoll, rtsig or /dev/poll.
--with-poll_module
--without-poll_module Enable or disable building a module to allow the server to use poll() method. This module will be built automatically if the platform does not support kqueue, epoll, rtsig or /dev/poll.
--without-http_gzip_module — Do not compile the compressed HTTP server response module. Compiling and running this module requires the zlib library.
--without-http_rewrite_module Do not compile the rewrite module. Compiling and running this module requires PCRE library support.
--without-http_proxy_module — Do not compile the http_proxy module.
--with-http_ssl_module
— Use the https protocol module. By default, this module is not built. The OpenSSL library is required to build and run this module.
--with-pcre=<code><em>path</em>
— Set the source code path of the PCRE library. The source code of the PCRE library (versions 4.4 - 8.30) needs to be downloaded and unzipped from the PCRE website. The rest of the work is done by Nginx's ./configure and make. Regular expressions are used in the location directive and the ngx_http_rewrite_module module.
--with-pcre-jit
— Compile PCRE with "just-in-time compilation" (in 1.1.12, pcre_jit directive).
--with-zlib=<code><em>path</em>
- Set the source code path of the zlib library. To download from zlib (versions 1.1.3 - 1.2.5) and unzip it. The rest of the work is done by Nginx's ./configure and make. The ngx_http_gzip_module module requires zlib.
--with-cc-opt=<code><em>parameters</em>
— Set additional parameters that will be added to the CFLAGS variable . For example, when you use the PCRE library on FreeBSD, you need to use: --with-cc-opt="-I /usr/local/include.
. If necessary, you need to add select() support Number of files
:--with-cc-opt="-D FD_SETSIZE=2048".
##--with-ld- opt=<code>parameters<em></em>
— Set additional parameters that will be used during linking. For example, when using the system's PCRE library under FreeBSD, you should specify: --with-ld-opt="-L /usr/local/lib".
1234567 | ##. / configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=../pcre-4.4 --with-zlib=../zlib-1.1.3 |
For more Nginx related technical articles, please visit the Nginx Tutorial column to learn!
The above is the detailed content of How to install nginx. For more information, please follow other related articles on the PHP Chinese website!