Home Backend Development PHP Tutorial nginx source code installation

nginx source code installation

Jul 30, 2016 pm 01:30 PM
nginx pcre usr zlib

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 instructionsapt-get install build-essential apt-get install libtoolcentos platform compilation environment use the following instructionsInstall make:yum -y install gcc automake autoconf libtool makeInstall g++:yum install gcc gcc-c++The following officially starts
------------ -------------------------------------------------- -------------
Generally we need to install pcre and zlib first, the former for rewrite and the latter for gzip compression.
1. Select the source code directory
It can be any directory. The one selected in this article is /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 code package. Use the following command to download, compile and install the PCRE package: 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 install3. Install the zlib library
http://zlib.net/zlib-1.2.8.tar.gz Download the latest zlib source code package, use the following command to download, compile and install the zlib package: 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 install4. Install ssl (some vps do not have ssl installed by default) cd /usr/local/src wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz tar -zxvf openssl-1.0.1c.tar.gz5. Install nginx Nginx generally has two versions, namely stable version and development version, you can choose one of these two versions according to your purpose. The following are the detailed steps to install Nginx to 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.1cmake 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 fastcgi.conf koi-win nginx.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-utf6. 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, netstat -ano|grep 80If Execute if no results are found. If there are results, ignore this step (ubuntu must be started with sudo, otherwise it can only run in the foreground) sudo /usr/local/nginx/nginxOpen the browser to access the IP of this machine. If the browser displays Welcome to nginx!, it means Nginx has been installed and running successfully. nginx source code installation------------------------------------------------ --------
The nginx installation is complete here. If you only process static html, you don’t need to continue the installation. If you need to process php scripts, you also need to install php-fpm. Installation troubleshooting belowAttachment: possible errors and some help information1.1 compile pcre errorlibtool: 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]Error2nginx source code installationSolution: install g++, don’t forget to reconfigureapt-get install g++ apt-get install build-essential make clean ./configure make1.2 make errormake: *** 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= option. Follow the installation method in step 4 or
apt-get install openssl apt-get install libssl-dev under ubuntucentosyum -y install openssl openssl-devel2.nginx compilation optionmake is used to compile. 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. nginx’s configure command supports the following parameters:
  • --prefix=<code><em>path</em>    定义一个目录,存放服务器上的文件 ,也就是nginx的安装目录。默认使用 /usr/local/nginx。
  • --sbin-path=<code><em>path</em> 设置nginx的可执行文件的路径,默认为  <code><em>prefix</em>/sbin/nginx.
  • --conf-path=<code><em>path</em>  设置在nginx.conf配置文件的路径。nginx允许使用不同的配置文件启动,通过命令行中的-c选项。默认为<code><em>prefix</em>/conf/nginx.conf.
  • --pid-path=<code><em>path</em>  设置nginx.pid文件,将存储的主进程的进程号。安装完成后,可以随时改变的文件名 , 在nginx.conf配置文件中使用 PID指令。默认情况下,文件名 为<code><em>prefix</em>/logs/nginx.pid.
  • --error-log-path=<code><em>path</em> 设置主错误,警告,和诊断文件的名称。安装完成后,可以随时改变的文件名 ,在nginx.conf配置文件中 使用 的error_log指令。默认情况下,文件名 为<code><em>prefix</em>/logs/error.log.
  • --http-log-path=<code><em>path</em>  设置主请求的HTTP服务器的日志文件的名称。安装完成后,可以随时改变的文件名 ,在nginx.conf配置文件中 使用 的access_log指令。默认情况下,文件名 为<code><em>prefix</em>/logs/access.log.
  • --user=<code><em>name</em>  设置nginx工作进程的用户。安装完成后,可以随时更改的名称在nginx.conf配置文件中 使用的 user指令。默认的用户名是nobody。
  • --group=<code><em>name</em>  设置nginx工作进程的用户组。安装完成后,可以随时更改的名称在nginx.conf配置文件中 使用的 user指令。默认的为非特权用户。
  • --with-select_module --without-select_module 启用或禁用构建一个模块来允许服务器使用select()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。
  • --with-poll_module --without-poll_module 启用或禁用构建一个模块来允许服务器使用poll()方法。该模块将自动建立,如果平台不支持的kqueue,epoll,rtsig或/dev/poll。
  • --without-http_gzip_module — 不编译压缩的HTTP服务器的响应模块。编译并运行此模块需要zlib库。
  • --without-http_rewrite_module  不编译重写模块。编译并运行此模块需要PCRE库支持。
  • --without-http_proxy_module — 不编译http_proxy模块。
  • --with-http_ssl_module — 使用https协议模块。默认情况下,该模块没有被构建。建立并运行此模块的OpenSSL库是必需的。
  • --with-pcre=<code><em>path</em> — 设置PCRE库的源码路径。PCRE库的源码(版本4.4 - 8.30)需要从PCRE网站下载并解压。其余的工作是Nginx的./ configure和make来完成。正则表达式使用在location指令和 ngx_http_rewrite_module 模块中。
  • --with-pcre-jit —编译PCRE包含“just-in-time compilation”(1.1.12中, pcre_jit指令)。
  • --with-zlib=<code><em>path</em> —设置的zlib库的源码路径。要下载从 zlib(版本1.1.3 - 1.2.5)的并解压。其余的工作是Nginx的./ configure和make完成。ngx_http_gzip_module模块需要使用zlib 。
  • --with-cc-opt=<code><em>parameters</em> — 设置额外的参数将被添加到CFLAGS变量。例如,当你在FreeBSD上使用PCRE库时需要使用:--with-cc-opt="-I /usr/local/include。.如需要需要增加 select()支持的文件数量:--with-cc-opt="-D FD_SETSIZE=2048".
  • --with-ld-opt=<code><em>parameters</em> —设置附加的参数,将用于在链接期间。例如,当在FreeBSD下使用该系统的PCRE库,应指定:--with-ld-opt="-L /usr/local/lib".
  • 典型实例(下面为了展示需要写在多行,执行时内容需要在同一行)./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源码安装,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to configure cloud server domain name in nginx How to configure cloud server domain name in nginx Apr 14, 2025 pm 12:18 PM

    How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

    How to check whether nginx is started How to check whether nginx is started Apr 14, 2025 pm 01:03 PM

    How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

    How to check nginx version How to check nginx version Apr 14, 2025 am 11:57 AM

    The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

    How to start nginx server How to start nginx server Apr 14, 2025 pm 12:27 PM

    Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

    How to create a mirror in docker How to create a mirror in docker Apr 15, 2025 am 11:27 AM

    Steps to create a Docker image: Write a Dockerfile that contains the build instructions. Build the image in the terminal, using the docker build command. Tag the image and assign names and tags using the docker tag command.

    How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

    You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

    How to run nginx apache How to run nginx apache Apr 14, 2025 pm 12:33 PM

    To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.

    How to check whether nginx is started? How to check whether nginx is started? Apr 14, 2025 pm 12:48 PM

    In Linux, use the following command to check whether Nginx is started: systemctl status nginx judges based on the command output: If "Active: active (running)" is displayed, Nginx is started. If "Active: inactive (dead)" is displayed, Nginx is stopped.

    See all articles