Nginx Source Installation

Source: Internet
Author: User
Tags epoll install openssl 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 UBUBTU platform compilation environment can use the following directives

Apt - Get Install build - essentialapt - 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 ++ 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 / srcwget FTP : //ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.34.tar.gz Tar - ZXVF pcre - 8.34 . Tar . GZCD pcre - 8.34 ./ Configuremakemake 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 / Srcwget http : //zlib.net/zlib-1.2.8.tar.gz Tar - ZXVF zlib - 1.2 . 8.tar . GZCD zlib - 1.2 . 8 ./ Configuremakemake Install 4. Install SSL (some VPS does not install SSL by default)

CD / usr / Local / Srcwget http : //www.openssl.org/source/openssl-1.0.1c.tar.gz Tar - ZXVF OpenSSL - 1.0 . 1c . Tar . GZ 5. 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 / Srcwget http : //nginx.org/download/nginx-1.4.2.tar.gz Tar - ZXVF Nginx - 1.4 . 2.tar . GZCD 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 Makemake 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 the installation is successful, the/usr/local/nginx directory is as follows

fastcgi . conf Koi - win Nginx . conf . default fastcgi . conf . default Logs scgi_paramsfastcgi_params mime . Types Scgi_params . default Fastcgi_params . default MIME . Types . default uwsgi_paramshtml nginx uwsgi_params . default Koi - UTF Nginx . conf Win - UTF 6. Start
Ensure that the 80 port of the system is not occupied by other programs, run the/usr/local/nginx/nginx command to start Nginx,

netstat - ano | grep the If the results are not found after the execution, the result is ignored this step (Ubuntu must be started with sudo, or can only be 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 Nginx is installed and running successfully.

-----------------------------------------------------
Here Nginx installation is complete, if you just deal with static HTML, you do not have to continue to install

If you need to work with PHP scripts, you also need to install PHP-FPM.

The following installation troubleshooting

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 1make[1]: Leaving directory '/usr/local/src/pcre-8.34 ' Make : *** [ All ] Error 2

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

Apt - Get Install G ++ Apt - Get Install build - Essentialmake Clean ./ Configuremake 1.2 Make Error

Make : *** No rule to make 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 Libraryinto the system, or build the OpenSSL library stat Ically from the Sourcewith nginx by using--with-openssl= option. Follow the installation method of step 4th or
Under Ubuntu

Apt - Get Install opensslapt - Get Install Libssl - Dev Under CentOS

Yum - y install OpenSSL OpenSSL - devel 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=pathDefine a directory that stores files on the server, which is the installation directory of Nginx. Default usage/usr/local/nginx。
  • --sbin-path=pathSets the path of the Nginx executable file, which defaults to prefix/sbin/nginx .
  • --conf-path=pathSet 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 设置nginx.pid文件,将存储的主进程的进程号。安装完成后,可以随时改变的文件名 , 在nginx.conf配置文件中使用 PID指令。默认情况下,文件名 为prefix/logs/nginx.pid.
  • --error-log-path=pathSets 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=pathSets 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=nameThe 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=nameSets 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 启用或禁用构建一个模块来允许服务器使用select()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。
  • --with-poll_module--without-poll_moduleenables 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-Do not compile the response module of the compressed HTTP server. Compiling and running this module requires a zlib library.
  • --without-http_rewrite_moduleThe rewrite module is not compiled. 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, 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.
  • --with-pcre-jit-compilation Pcre contains "Just-in-time compilation" (1.1.12, Pcre_jit instructions).
  • --with-zlib=path-Set 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 to 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。 . Add as needed select()支持的文件数量 :--with-cc-opt="-D FD_SETSIZE=2048".
  • --with-ld-opt=parameters-Set 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 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

    The above describes the Nginx source installation, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

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