Mainly refer to this article:
Http://www.nginx.cn/install
The only place to pay attention to IS
Replace the pcre-8.34.tar.gz with a new version, and of course the author has given a hint to download the latest Pcre source pack in the article. Currently the oldest version of the directory is 8.36; Keep up with the latest stable version as much as possible.
Here is the complete content of the article, very detailed description.
nginx Installation Nginx can be installed using the default packages for each platform, this article introduces the use of source code to compile the installation, including specific compilation parameter information.
Before the formal start, the compilation environment GCC g++ Development Library and so on needs to be installed in advance, where the default you have installed.
The UBUBTU platform compilation environment can use the following directives
Apt-get Install build-essential
apt-get Install Libtool
The CentOS Platform compilation environment uses the following directives
Install Make:
Yum-y install gcc automake autoconf libtool make
Install g++:
Yum Install gcc gcc-c++
Here we go.
---------------------------------------------------------------------------
Generally we all need to first install Pcre, Zlib, the former in order to rewrite the rewrite, the latter for gzip compression.
1. Selected Source Directory
Can be any directory, this article is selected/USR/LOCAL/SRC
Cd/usr/local/src
2. Install Pcre Library
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Download the latest Pcre source package and download the build and install Pcre package using the following command:
CD/USR/LOCAL/SRC
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz
TAR-ZXVF pcre-8.34.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 and download the build and install Zlib package using the following command:
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 default does not install SSL)
CD/USR/LOCAL/SRC
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
TAR-ZXVF Openssl-1.0.1c.tar.gz
5. Install Nginx
Nginx typically has two versions, stable and development, you can choose one of these two versions for your purposes, and the following are detailed steps for installing Nginx into the/usr/local/nginx directory:
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=/usr/local/src/ pcre-8.34 \
--with-zlib=/usr/local/src/zlib-1.2.8 \
--with-openssl=/usr/local/src/openssl-1.0.1c
Make make
Install
--with-pcre=/usr/src/pcre-8.34 refers to the pcre-8.34 source path.
--with-zlib=/usr/src/zlib-1.2.7 refers to the zlib-1.2.7 source path.
After successful installation, the following/usr/local/nginx directory
fastcgi.conf koi-win nginx.conf.default
fastcgi.conf.default logs
scgi_params 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 the system's 80 ports are not occupied by other programs, run the/usr/local/nginx/nginx command to start the Nginx,
Netstat-ano|grep 80
If the results are not found, the result is ignored this step (Ubuntu must be started with sudo, otherwise it can only run in the foreground)
Sudo/usr/local/nginx/nginx
Open the browser to access the IP of this machine, if the browser appears Welcome to nginx! Indicates that the Nginx has been installed and running successfully.
-----------------------------------------------------
Here the Nginx is done, and if you just process static HTML, you don't have to install it.
If you need to process PHP scripts, you will also need to install PHP-FPM.
The following installation is wrong
attachment: Possible errors and some help information
1.1 Compile Pcre error
libtool:compile:unrecognized option '-dhave_config_h '
libtool:compile:Try ' Libtool--help ' for more information.< C3/>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 configure again
Apt-get Install g++
apt-get install build-essential make clean
./configure
Make
1.2 make error
Make: * * * "rule" to "make target" build ", needed by ' default '. Stop.
/CONFIGURE:ERROR:SSL modules require the OpenSSL library.
You can either don't 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= option.
Follow the installation method in step 4th or
Ubuntu under
Apt-get Install OpenSSL
apt-get install Libssl-dev
CentOS under
Yum-y Install OpenSSL Openssl-devel
2.nginx Compilation Options
Make is compiled to read instructions from the makefile and compile them.
Make install is used for installation, and it also reads instructions from makefile to install to a specified location.
The Configure command is used to detect the target features of your installation platform. It defines all aspects of the system, including Nginx's allowed connection handling, such as it detects if you have CC or GCC, does not need CC or GCC, it is a shell script, and at the end of execution it creates a makefile file. The Nginx Configure command supports the following parameters:--prefix=path Defines a directory that holds the file   on the server, which is the Nginx installation directory. /usr/local/nginx is used by default. --sbin-path=path sets the path of the Nginx executable file, which defaults to prefix/sbin/nginx. --conf-path=path set the path to the nginx.conf configuration file. Nginx allows you to start with a different configuration file, using the-C option on the command line. Default is prefix/conf/nginx.conf. --pid-path=path sets the Nginx.pid file, the process number of the main process that will be stored. After the installation is complete, you can change the file name at any time, using the PID directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/nginx.pid. --error-log-path=path sets the name of the main error, warning, and diagnostic file. After the installation is complete, you can change the file name at any time, using the Error_log directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/error.log. --http-log-path=path the name of the log file for the HTTP server on which the master request is set. After the installation is complete, you can change the file name at any time, using the Access_log directive in the nginx.conf configuration file. By default, the file name is Prefix/logs/access.log. --user=name the user who set up the Nginx worker process. The user directive used in the Nginx.conf configuration file can be changed at any time after the installation is complete. The default user name is nobody. --group=name sets the user group for the Nginx worker process. The user directive used in the Nginx.conf configuration file can be changed at any time after the installation is complete. The default is not a privileged user. --with-select_module --without-select_module enables or disables building a module to allow the server to use the Select () method. The module will be automatically built if the platform does not support Kqueue,epoll,rtsig or/dev/poll. --with-poll_module --without-poll_module enables or disables building a module to allow the server to use the poll () method. The module will be automatically built if the platform does not support Kqueue,epoll,rtsig or/dev/poll. --without-http_gzip_module -a response module that does not compile a compressed HTTP server. Compiling and running this module requires a zlib library. --without-http_rewrite_module does not compile the rewrite module. Compiling and running this module requires PCRE library support. --without-http_proxy_module -does not compile Http_proxy modules. --with-http_ssl_module -uses the HTTPS protocol module. By default, the module is not built. It is necessary to establish and run the OpenSSL library for this module. --with-pcre=path - set the source path for the Pcre library. The source code (version 4.4-8.30) of the Pcre library needs to be downloaded and decompressed from the Pcre website. The rest of the work is nginx./configure and make to complete. Regular expressions are used in location directives and ngx_http_rewrite_module modules. --with-pcre-jit -compilation Pcre contains "Just-in-time compilation" (1.1.12, Pcre_jit directives). --with-zlib=path -set the source path for the zlib library. To download and extract from the zlib (version 1.1.3-1.2.5). The rest of the work is nginx./configure and make complete. The Ngx_http_gzip_module module requires the use of zlib. --with-cc-opt=parameters -setting additional parameters 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 you need to increase the number of select () supported files,--with-cc-opt= "-D fd_setsize=2048". --with-ld-opt=parameters -sets the additional parameters that will be used during the link. For example, when using the Pcre Library of the system under FreeBSD, you should specify:--with-ld-opt= "-l/usr/local/lib".
Typical example (below to show the need to write on multiple lines, the content needs to be on the same line at execution time)
./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