NGINX的编译安装

  • NGINX的编译安装已关闭评论
  • 108 次浏览
  • A+
所属分类:linux技术
摘要

1.安装编译工具2.创建运行NGINX的转有程序3.下载源码包并解压4.使用configure脚本生成makefile文件


实现步骤:

  • 1.安装编译工具

  • 2.创建运行NGINX的转有程序

  • 3.下载源码包并解压

  • 4.使用configure脚本生成makefile文件

  • 5.编译安装

  • 6.创建service文件

说明:

  源码安装需要提前准备标准的编译器,GCC的全称是(GNU Compiler collection),其有GNU开发,并以GPL即LGPL许可,是自由的类UNIX即苹果电脑Mac OS X操作系统的标准编译器,因为GCC原本只能处理C语言,所以原名为GNU C语言编译器,后来得到快速发展,可以处理C++,Fortran,pascal,objectiveC,java以及Ada等其他语言,此外还需要Automake工具,以完成自动创建Makefile的工作,Nginx的一些模块需要依赖第三方库,比如: pcre(支持rewrite),zlib(支持gzip模块)和openssl(支持ssl模块)等。

范例:CentOS8 编译安装nginx1.8

#安装编译工具 [root@CentOS8 ~]# yum -y install gcc make  pcre-devel openssl-devel zlib-devel   #创建转有用户 [root@CentOS8 ~]# useradd -r -s /sbin/nologin nginx  [root@CentOS8 ~]# id nginx uid=988(nginx) gid=984(nginx) groups=984(nginx)  #下载软件包 地址: https://nginx.org/en/download.html  http://nginx.org/download/  #解压源码包并编译 [root@CentOS8 nginx-1.18.0]#  mkdir /apps/nginx -p  [root@CentOS8 nginx-1.18.0]# ./configure --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --prefix=/apps/nginx  [root@CentOS8 nginx-1.18.0]# make -j 4 && make isntall Configuration summary   + using system PCRE library   + using system OpenSSL library   + using system zlib library    nginx path prefix: "/apps/nginx"   nginx binary file: "/apps/nginx/sbin/nginx"   nginx modules path: "/apps/nginx/modules"   nginx configuration prefix: "/apps/nginx/conf"   nginx configuration file: "/apps/nginx/conf/nginx.conf"   nginx pid file: "/apps/nginx/logs/nginx.pid"   nginx error log file: "/apps/nginx/logs/error.log"   nginx http access log file: "/apps/nginx/logs/access.log"   nginx http client request body temporary files: "client_body_temp"   nginx http proxy temporary files: "proxy_temp"   nginx http fastcgi temporary files: "fastcgi_temp"   nginx http uwsgi temporary files: "uwsgi_temp"   nginx http scgi temporary files: "scgi_temp"  #创建service文件 [root@CentOS8 conf]# mkdir run  [root@CentOS8 conf]# vim conf/nginx.conf pid        run/nginx.pid;   [root@CentOS8 ~]# vim /usr/lib/systemd/system/nginx.service [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target  [Service] Type=forking PIDFile=/apps/nginx/run/nginx.pid ExecStart=/apps/nginx/sbin/nginx -c /apps/nginx/conf/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID LimitNOFILE=100000 [Install] WantedBy=multi-user.target