search
HomeBackend DevelopmentPHP Tutorialnginx source code installation

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
    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
    内存飙升!记一次nginx拦截爬虫内存飙升!记一次nginx拦截爬虫Mar 30, 2023 pm 04:35 PM

    本篇文章给大家带来了关于nginx的相关知识,其中主要介绍了nginx拦截爬虫相关的,感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。

    nginx限流模块源码分析nginx限流模块源码分析May 11, 2023 pm 06:16 PM

    高并发系统有三把利器:缓存、降级和限流;限流的目的是通过对并发访问/请求进行限速来保护系统,一旦达到限制速率则可以拒绝服务(定向到错误页)、排队等待(秒杀)、降级(返回兜底数据或默认数据);高并发系统常见的限流有:限制总并发数(数据库连接池)、限制瞬时并发数(如nginx的limit_conn模块,用来限制瞬时并发连接数)、限制时间窗口内的平均速率(nginx的limit_req模块,用来限制每秒的平均速率);另外还可以根据网络连接数、网络流量、cpu或内存负载等来限流。1.限流算法最简单粗暴的

    nginx+rsync+inotify怎么配置实现负载均衡nginx+rsync+inotify怎么配置实现负载均衡May 11, 2023 pm 03:37 PM

    实验环境前端nginx:ip192.168.6.242,对后端的wordpress网站做反向代理实现复杂均衡后端nginx:ip192.168.6.36,192.168.6.205都部署wordpress,并使用相同的数据库1、在后端的两个wordpress上配置rsync+inotify,两服务器都开启rsync服务,并且通过inotify分别向对方同步数据下面配置192.168.6.205这台服务器vim/etc/rsyncd.confuid=nginxgid=nginxport=873ho

    nginx php403错误怎么解决nginx php403错误怎么解决Nov 23, 2022 am 09:59 AM

    nginx php403错误的解决办法:1、修改文件权限或开启selinux;2、修改php-fpm.conf,加入需要的文件扩展名;3、修改php.ini内容为“cgi.fix_pathinfo = 0”;4、重启php-fpm即可。

    如何解决跨域?常见解决方案浅析如何解决跨域?常见解决方案浅析Apr 25, 2023 pm 07:57 PM

    跨域是开发中经常会遇到的一个场景,也是面试中经常会讨论的一个问题。掌握常见的跨域解决方案及其背后的原理,不仅可以提高我们的开发效率,还能在面试中表现的更加

    nginx部署react刷新404怎么办nginx部署react刷新404怎么办Jan 03, 2023 pm 01:41 PM

    nginx部署react刷新404的解决办法:1、修改Nginx配置为“server {listen 80;server_name https://www.xxx.com;location / {root xxx;index index.html index.htm;...}”;2、刷新路由,按当前路径去nginx加载页面即可。

    Linux系统下如何为Nginx安装多版本PHPLinux系统下如何为Nginx安装多版本PHPMay 11, 2023 pm 07:34 PM

    linux版本:64位centos6.4nginx版本:nginx1.8.0php版本:php5.5.28&php5.4.44注意假如php5.5是主版本已经安装在/usr/local/php目录下,那么再安装其他版本的php再指定不同安装目录即可。安装php#wgethttp://cn2.php.net/get/php-5.4.44.tar.gz/from/this/mirror#tarzxvfphp-5.4.44.tar.gz#cdphp-5.4.44#./configure--pr

    nginx怎么禁止访问phpnginx怎么禁止访问phpNov 22, 2022 am 09:52 AM

    nginx禁止访问php的方法:1、配置nginx,禁止解析指定目录下的指定程序;2、将“location ~^/images/.*\.(php|php5|sh|pl|py)${deny all...}”语句放置在server标签内即可。

    See all articles

    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

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Tools

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    ZendStudio 13.5.1 Mac

    ZendStudio 13.5.1 Mac

    Powerful PHP integrated development environment

    MinGW - Minimalist GNU for Windows

    MinGW - Minimalist GNU for Windows

    This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

    VSCode Windows 64-bit Download

    VSCode Windows 64-bit Download

    A free and powerful IDE editor launched by Microsoft

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools