Nginx installation using source code

Source: Internet
Author: User
Tags epoll openssl library



Nginx can be installed using the default packages of each platform, this article is to introduce the use of source code compilation installation, including specific compilation parameters information.

Before the official start, the compilation environment GCC g++ Development Library and so on need to be installed in advance, here by default you have installed.


The following officially begins
---------------------------------------------------------------------------
Generally we need to first install Pcre, Zlib, the former in order to rewrite rewrite, the latter in order to gzip compression.
1. Select the source directory
Can be any directory, this article is selected/USR/LOCAL/SRC
Cd/usr/local/src


2. Installing the Pcre Library
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/Download the latest pcre source package, download the compile and install the Pcre package using the command below:

Cd/usr/local/src

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
TAR-ZXVF pcre-8.35.tar.gz
CD pcre-8.35
./configure
Make
Make install




3. Installing the Zlib Library
http://zlib.net/zlib-1.2.8.tar.gz Download the latest zlib source package, download the compile and install the zlib package using the command below:

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

3. Installing Nginx

Nginx generally has two versions, the stable version and the development version, you can choose one of these two versions according to your purpose, below is the detailed steps of installing nginx into the/usr/local/nginx directory:

Cd/usr/local/src

wget http://nginx.org/download/nginx-1.3.10.tar.gz
TAR-ZXVF nginx-1.3.10.tar.gz
CD nginx-1.3.10
./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.35--with-zlib=/usr/local/src/zlib-1.2.8
Make
Make install

--with-pcre=/usr/src/pcre-8.35 refers to the pcre-8.35 source path.
--with-pcre=/usr/src/zlib-1.2.8 refers to the zlib-1.2.8 source path.


After the installation is successful, the/usr/local/nginx directory is as follows



Ensure that the 80 port of the system is not occupied by other programs, run the/usr/local/nginx/nginx command to start Nginx,

Sudo/usr/local/nginx/nginx (must be started with sudo under Ubuntu, otherwise it can only be run in the foreground)

Open the browser to access the IP of this machine if the browser appears Welcome to nginx! Indicates that Nginx is installed and running successfully.



Attached: Errors and some help information that may be encountered

1.1 Compilation Pcre Error

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.35 '
Make: * * * [ALL] Error 2



Workaround: Install g++, don't forget to re-configure

Apt-get Install g++

Apt-get Install Build-essential

Make clean

./configure

Make



1.2 Make Error
Make: * * * No rule to do target ' build ', needed by ' default '. Stop.
./CONFIGURE:ERROR:SSL modules require the OpenSSL library.
You can either does 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 3.1 or add--with-openssl=<path>
Cd/usr/local/src
wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
TAR-ZXVF openssl-1.0.1c.tar.gz
Re-compiling
Cd.. /nginx-1.2.3
./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.35--with-zlib=/usr/local/src/zlib-1.2.8 --with-openssl=/usr/local/src/openssl-1.0.1c





2.nginx compilation options

Make is used to compile, it reads the instruction from the makefile, and then compiles.

The make install is used to install, and it also reads instructions from makefile and installs 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 Nginx's allowed connection processing methods, such as it detects if you have CC or GCC, does not require 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 stores files on the server, which is the installation directory of Nginx. /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 via the-C option on the command line. The default is prefix/conf/nginx.conf.
--pid-path=path sets the Nginx.pid file that will store the process number of the main process. After the installation is complete, you can change the file name at any time by 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 primary 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 sets the name of the log file for the HTTP server for the primary request. 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 the Nginx worker process. After the installation is complete, you can change the name of the user directive that is used in the nginx.conf configuration file at any time. The default user name is nobody.
--group=name sets the user group for the Nginx worker process. After the installation is complete, you can change the name of the user directive that is used in the nginx.conf configuration file at any time. The default is non-privileged users.
--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 created automatically 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 created automatically if the platform does not support Kqueue,epoll,rtsig or/dev/poll.
--without-http_gzip_module-does not compile the Response module for compressed HTTP servers. 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 the Http_proxy module.
The--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 of the Pcre library. The source code of the Pcre Library (version 4.4-8.30) 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 the location directive and in the Ngx_http_rewrite_module module.
The--with-pcre-jit-compilation Pcre contains "Just-in-time compilation" (1.1.12, Pcre_jit instructions).
--with-zlib=path-sets the source path of the zlib library. To download and unzip from 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-set additional parameters will be added to the cflags variable. For example, when you use the Pcre library on FreeBSD, you need to use the following:--with-cc-opt= "-i/usr/local/include: If you need to increase the number of files supported by select (),--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 system's Pcre library under FreeBSD, you should specify:--with-ld-opt= "-l/usr/local/lib".

Typical instances (below in order to demonstrate the need to write on multiple lines, the content needs to be on the same line at execution)

./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

Nginx installation using source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.