Install nginx source code

Source: Internet
Author: User
Tags epoll openssl library
: This article describes how to install nginx source code. For more information about PHP tutorials, see. Nginx can be installed using the default packages on various platforms. This article describes how to use the source code for compilation and installation, including the specific compilation parameter information.

Before the official start, you need to install the gcc g ++ development library in the compiling environment in advance. you have installed it by default.

You can use the following commands to compile the ububtu platform environment:

Apt-get install build-essential tialapt-get install libtool Use the following commands in the centos compiling environment:

Install make:

Yum-y install gcc automake autoconf libtool make Install g ++:

Yum install gcc-c ++ Start Now
---------------------------------------------------------------------------
Generally, we need to install pcre and zlib first. The former is used to rewrite, and the latter is used to compress gzip.
1. select the source code directory
This document selects/usr/local/src.

Cd/usr/local/src 2. install the PCRE library
Ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ download the latest PCRE source package, use the following command to download the compilation and installation of PCRE package:

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. install the zlib library
Http://zlib.net/zlib-1.2.8.tar.gz to download the latest zlib source package, use the following command to download the compilation and installation of zlib package:

Cd/usr/local/srcwget http://zlib.net/zlib-1.2.8.tar.gztar-zxvf zlib-1.2.8.tar.gzcd zlib-1.2.8./configuremakemake install 4. install ssl (ssl is not installed in some vps by default)

Cd/usr/local/srcwget http://www.openssl.org/source/openssl-1.0.1c.tar.gztar-zxvf openssl-1.0.1c.tar.gz. 5. install nginx

Nginx generally has two versions: stable version and development version. you can select one of these two versions based on your purpose, the following describes how to install Nginx in the/usr/local/nginx Directory:

Cd/usr/local/srcwget http://nginx.org/download/nginx-1.4.2.tar.gztar-zxvf nginx-1.4.2.tar.gzcd nginx-1.4.2. /configure -- sbin-path =/usr/local/nginx \ -- conf-path =/usr/local/nginx. conf \ -- pid-path =/usr/local/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.1cmakemake install -- With-pcre =/usr/src/pcre-8.34 refers to the source code path of the pcre-8.34.
-- With-zlib =/usr/src/zlib-1.2.7 refers to the source code path of the zlib-1.2.7.

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

Fastcgi. conf koi-win nginx. conf. defaultfastcgi. conf. default logs scgi_paramsfastcgi_params mime. types prepare mime. types. default uwsgi_paramshtml nginx uwsgi_params.defaultkoi-utf nginx. conf win-utf 6. start
Ensure that Port 80 of the system is not occupied by other programs. run the/usr/local/nginx command to start Nginx,

Netstat-ano | grep 80 If no result is found, run the command. If no result is found, ignore this step. (sudo must be enabled in ubuntu; otherwise, it can only run on the foreground)

Sudo/usr/local/nginx Open the browser to access the IP address of this machine. if the browser displays Welcome to nginx! Nginx has been installed and runs successfully.

-----------------------------------------------------
Nginx is installed here. if you only process static html, you do not need to continue the installation.

If you need to process the php script, you also need to install php-fpm.

The following installation troubleshooting

Appendix: possible errors and some help information

1.1 pcre compilation 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.34 'make: *** [all] Error2

Solution: install g ++. do not forget to re-configure

Apt-get install g ++ apt-get install build-essential tialmake 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 do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using -- with-openssl = option. Follow the installation method in step 2 or
Under ubuntu

Apt-get install opensslapt-get install libssl-dev Under centos

Yum-y install openssl-devel 2. nginx compilation options

Make is used for Compilation. it reads commands from Makefile and then compiles the commands.

Make install is used for installation. it also reads commands from Makefile and installs them to the specified location.

The configure command is used to detect the target features of your installation platform. It defines all aspects of the system, including the method for handling nginx connections that are allowed. for example, it will detect whether you have CC or GCC, and does not need CC or GCC, it is a shell script. at the end of execution, it creates a Makefile file. The configure command of nginx supports the following parameters:

  • --prefix=pathDefine a directory to store files on the server, that is, the nginx installation directory. Default usage/usr/local/nginx。
  • --sbin-path=pathSet the path of the nginx executable file. the default value isprefix/sbin/nginx.
  • --conf-path=pathSet the path in the nginx. conf configuration file. Nginx can be started using different configuration files through the-c option in the command line. Default value:prefix/conf/nginx.conf.
  • -- Pid-path =PathSet the nginx. pid file to the process number of the stored master process. After the installation is complete, you can change the file name at any time and use the PID command in the nginx. conf configuration file. By default, the file name isprefix/logs/nginx.pid.
  • --error-log-path=pathSet the name of the master error, warning, and diagnostic file. After the installation is complete, you can change the file name at any time and use the error_log command in the nginx. conf configuration file. By default, the file name isprefix/logs/error.log.
  • --http-log-path=pathSet the name of the log file of the HTTP server of the master request. After the installation is complete, you can change the file name at any time and use the access_log command in the nginx. conf configuration file. By default, the file name isprefix/logs/access.log.
  • --user=nameSet the nginx worker process. After the installation is complete, you can change the user command used in the nginx. conf configuration file at any time. The default user name is nobody.
  • --group=nameSet the user group of the nginx worker process. After the installation is complete, you can change the user command used in the nginx. conf configuration file at any time. By default, it is a non-privileged user.
  • --with-select_module -- The without-select_module enables or disables building a module to allow the server to use the select () method. This module is automatically created if the platform does not support kqueue, epoll, rtsig or/dev/poll.
  • --with-poll_module --without-poll_moduleEnable or disable building a module to allow the server to use the poll () method. This module is automatically created 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. The zlib library is required to compile and run this module.
  • --without-http_rewrite_moduleDo not compile and rewrite the module. Compiling and running this module requires support from the PCRE library.
  • --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. It is necessary to establish and run the OpenSSL library of this module.
  • --with-pcre=path-Set the source code 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 done by Nginx./configure and make. The regular expression is used in the location command and the ngx_http_rewrite_module module.
  • --with-pcre-jit-Compile PCRE to include "just-in-time compilation" (pcre_jit command in 1.1.12 ).
  • --with-zlib=path-Set the source code path of the zlib library. Download and decompress zlib (version 1.1.3-1.2.5. The rest of the work is done by Nginx./configure and make. The ngx_http_gzip_module must use zlib.
  • --with-cc-opt=parameters-Setting additional parameters will be added to the CFLAGS variable. For example, you need to use the PCRE library on FreeBSD:--with-cc-opt="-I /usr/local/include。. Add as neededNumber of files supported by select ():--with-cc-opt="-D FD_SETSIZE=2048".
  • --with-ld-opt=parameters-Set additional parameters to be used during the link. For example, if you use the PCRE library of the system in FreeBSD, specify:--with-ld-opt="-L /usr/local/lib".
  • Typical instance (the following content must be written in the same row to show multiple rows)

    . /Configure -- sbin-path =/usr/local/nginx -- conf-path =/usr/local/nginx. conf -- pid-path =/usr/local/nginx. pid -- with-http_ssl_module -- with-pcre = .. /pcre-4.4 -- with-zlib = .. zlib-1.1.3

    The above introduces the installation of nginx source code, including some content, and hope to be helpful to friends who are interested in PHP tutorials.

    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.