一、Nginx简介

官方网址:http://nginx.org/

Nginx是由1994年毕业于俄罗斯国立莫斯科鲍曼科技大学的同学为俄罗斯rambler.ru公司开发的,开发工作最早从2002年开始,第一次公开发布时间是2004年10月4日,版本号是0.1.0

Nginx的版本分为开发版、稳定版和过期版,nginx以功能丰富著称,它即可以作为http服务器,也可以作为反向代理服务器或者邮件服务器,能够快速的响应静态网页的请求,支持FastCGI/SSL/Virtual Host/URL Rwrite/Gzip/HTTP Basic Auth等功能,并且支持第三方的功能扩展。

Nginx是单进程单线程模型,即启动的工作进程只有一个进程响应客户端请求,不像apache可以在一个进程内启动多个线程响应可请求,因此在内存占用上比apache小的很多。Nginx维持一万个非活动会话只要2.5M内存。Nginx和Mysql是CPU密集型的,就是对CPU的占用比较大,默认session在本地文件保存,支持将session保存在memcache,但是memcache默认支持最大1M的课hash对象。

二、实验环境

操作系统:CentOS6.5

Nginx版本:nginx-1.14.0

三、安装

1.依赖环境介绍

gcc gcc-c++

gcc为GNU Compiler Collection的缩写,可以编译C和C++源代码等,它是GNU开发的C和C++以及其他很多种语言 的编译器(最早的时候只能编译C,后来很快进化成一个编译多种语言的集合,如Fortran、Pascal、Objective-C、Java、Ada、 Go等。)
gcc 在编译C++源代码的阶段,只能编译 C++ 源文件,而不能自动和 C++ 程序使用的库链接(编译过程分为编译、链接两个阶段,注意不要和可执行文件这个概念搞混,相对可执行文件来说有三个重要的概念:编译(compile)、链接(link)、加载(load)。源程序文件被编译成目标文件,多个目标文件连同库被链接成一个最终的可执行文件,可执行文件被加载到内存中运行)。因此,通常使用 g++ 命令来完成 C++ 程序的编译和连接,该程序会自动调用 gcc 实现编译。
gcc-c++也能编译C源代码,只不过把会把它当成C++源代码,后缀为.c的,gcc把它当作是C程序,而g++当作是c++程序;后缀为.cpp的,两者都会认为是c++程序,注意,虽然c++是c的超集,但是两者对语法的要求是有区别的。

make automake

make是一个用来控制可执行文件和其他一些从源文件来的非源代码文件版本的软件。Make可以从一个名为makefile的文件中获得如何构建你所写程序的依赖关系,Makefile中列出了每个目标文件以及如何由其他文件来生成它。
automake是一个从Makefile.am文件自动生成Makefile.in的工具。为了生成Makefile.in,automake还需用到perl,由于automake创建的发布完全遵循GNU标准,所以在创建中不需要perl。libtool是一款方便生成各种程序库的工具。

autoconf

autoconf是用来生成自动配置软件源代码脚本(configure)的工具

pcre pcre-devel

在Nginx编译需要 PCRE(Perl Compatible Regular Expression),因为Nginx 的Rewrite模块和HTTP 核心模块会使用到PCRE正则表达式语法。

zlip zlib-devel

nginx启用压缩功能的时候,需要此模块的支持。

openssl openssl-devel

开启SSL的时候需要此模块的支持。

libtool

libtool是一个通用库支持脚本,将使用动态库的复杂性隐藏在统一、可移植的接口中;使用libtool的标准方法,可以在不同平台上创建并调用动态库。
libtool主要的一个作用是在编译大型软件的过程中解决了库的依赖问题;将繁重的库依赖关系的维护工作承担下来,从而释放了程序员的人力资源。libtool提供统一的接口,隐藏了不同平台间库的名称的差异等细节,生成一个抽象的后缀名为la高层库libxx.la(其实是个文本文件),并将该库对其它库的依赖关系,都写在该la的文件中。

2.依赖环境安装

[root@herui ~]# yum -y install gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel libtool
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
Setting up Install Process
Package gcc-4.4.-.el6_9..x86_64 already installed and latest version
Package :make-3.81-.el6.x86_64 already installed and latest version
Package automake-1.11.-.el6.noarch already installed and latest version
Package autoconf-2.63-5.1.el6.noarch already installed and latest version
Package zlib-1.2.-.el6.x86_64 already installed and latest version
Package libtool-2.2.-15.5.el6.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 :4.4.-.el6_9. will be installed
--> Processing Dependency: libstdc++-devel = 4.4.-.el6_9. for package: gcc-c++-4.4.-.el6_9..x86_64
--> Processing Dependency: libstdc++ = 4.4.-.el6_9. for package: gcc-c++-4.4.-.el6_9..x86_64
---> Package openssl.x86_64 :1.0.1e-.el6 will be updated
---> Package openssl.x86_64 :1.0.1e-.el6 will be an update
... ...
... ...
... ...
Installed:
gcc-c++.x86_64 :4.4.-.el6_9. openssl-devel.x86_64 :1.0.1e-.el6 pcre-devel.x86_64 :7.8-.el6
zlib-devel.x86_64 :1.2.-.el6 Dependency Installed:
keyutils-libs-devel.x86_64 :1.4-.el6 krb5-devel.x86_64 :1.10.-.el6
libcom_err-devel.x86_64 :1.41.-.el6 libkadm5.x86_64 :1.10.-.el6
libselinux-devel.x86_64 :2.0.-.el6 libsepol-devel.x86_64 :2.0.-.el6
libstdc++-devel.x86_64 :4.4.-.el6_9. Updated:
openssl.x86_64 :1.0.1e-.el6 pcre.x86_64 :7.8-.el6 Dependency Updated:
e2fsprogs.x86_64 :1.41.-.el6 e2fsprogs-libs.x86_64 :1.41.-.el6
keyutils.x86_64 :1.4-.el6 keyutils-libs.x86_64 :1.4-.el6
krb5-libs.x86_64 :1.10.-.el6 krb5-workstation.x86_64 :1.10.-.el6
libcom_err.x86_64 :1.41.-.el6 libselinux.x86_64 :2.0.-.el6
libselinux-python.x86_64 :2.0.-.el6 libselinux-utils.x86_64 :2.0.-.el6
libss.x86_64 :1.41.-.el6 libstdc++.x86_64 :4.4.-.el6_9. Complete!

3.下载Nginx安装包

[root@herui tmp]# wget http://nginx.org/download/nginx-1.14.0.tar.gz
---- ::-- http://nginx.org/download/nginx-1.14.0.tar.gz
Resolving nginx.org... 95.211.80.227, 206.251.255.63, :::::3f, ...
Connecting to nginx.org|95.211.80.227|:... connected.
HTTP request sent, awaiting response... Found
Location: http://113.215.26.194/files/71490000007FAB32/nginx.org/download/nginx-1.14.0.tar.gz [following]
---- ::-- http://113.215.26.194/files/71490000007FAB32/nginx.org/download/nginx-1.14.0.tar.gz
Connecting to 113.215.26.194:... connected.
HTTP request sent, awaiting response... OK
Length: (992K) [application/octet-stream]
Saving to: “nginx-1.14..tar.gz” %[==================================================================>] ,, 1.29M/s in .8s -- :: (1.29 MB/s) - “nginx-1.14..tar.gz” saved [/]

3.解压nginx-1.14.0.tar.gz

[root@herui tmp]# tar -zxvf nginx-1.14..tar.gz -C /usr/local/src/
[root@herui nginx-1.14.]# pwd
/usr/local/src/nginx-1.14.
[root@herui nginx-1.14.]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src

4.侦测程序,生成MakeFile文件

[root@herui nginx-1.14.0]# ./configure  --prefix=/usr/local/nginx  --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log  --http-log-path=/var/log/nginx/access.log  --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock  --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre

5.安装:make install

[root@herui nginx-1.14.]# make && make install

6.启动、停止Nginx服务

[root@herui ~]# /usr/local/nginx/sbin/nginx   #启动Nginx
nginx: [emerg] getpwnam("nginx") failed #没有Nginx用户
[root@herui ~]# /usr/local/nginx/sbin/nginx -s stop #停止Nginx
[root@herui ~]# /usr/local/nginx/sbin/nginx -s reload #不停止服务,重新加载配置文件

7.验证Nginx是否开启成功

[root@herui ~]# ps aux|grep nginx
root 0.0 0.1 ? Ss : : nginx: master process /usr/local/nginx/sbin/nginx
nginx 0.0 0.1 ? S : : nginx: worker process
root 0.0 0.0 pts/ S+ : : grep nginx

8.在浏览器中打开,效果如下

四、说明

1.在编译过程中,如果/usr/local/nginx目录不存在,make install会自动创建

2.在安装之前,先创建好nginx用户和nginx用户组

Nginx之一:Nginx的编译安装的更多相关文章

  1. 新安装和已安装nginx如何添加未编译安装模块/补丁

    新安装和已安装nginx如何添加未编译安装模块/补丁 --http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10485& ...

  2. 安装成功的nginx如何添加未编译安装模块

    原已经安装好的nginx,现在需要添加一个未被编译安装的模块举例说明:安装第三方的ngx_cache_purge模块(用于清除指定URL的缓存)nginx的模块是需要重新编译nginx,而不是像apa ...

  3. nginx的下载、编译安装和启动

    一.nginx简介 nginx(“engine x”)是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器.nginx是由Igor Sysoev为俄罗斯访问量第二的R ...

  4. centos 7 下 nginx 1.10.3 编译安装的方法

    安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境. 一. gcc 安装安装 nginx 需要先 ...

  5. [nginx] 从源码编译安装NGINX

    nginx通过rpm包进行的安装和配置: [web][nginx] 初识nginx -- 使用nginx搭建https DPI解码测试环境 现在,要通过源码进行安装. 参考:https://nginx ...

  6. F-stack及其Nginx、redis的编译安装

    F-stack简介 F-stack粘合了dpdk.用户态协议栈和nginx.redis,弥补了dpdk没有协议栈的不足,并用nginx.redis提供了一个调用应用程序的接口. Quick Start ...

  7. 转:安装成功的nginx如何添加未编译安装模块

    原已经安装好的nginx,现在需要添加一个未被编译安装的模块 举例说明:安装第三方的ngx_cache_purge模块(用于清除指定URL的缓存) nginx的模块是需要重新编译nginx,而不是像a ...

  8. Nginx之解压编译安装-yellowcong

    安装前准备 对于nginx编译安装需要先安装编译 的工具,然后再安装nginx依赖 yum -y install gcc gcc-c++ autoconf automake make yum -y i ...

  9. 生产线上的Nginx如何添加未编译安装模块

    正在生产线上跑着web前端是nginx+tomcat,现在有这样一个需求,需要对网站的单品页面和列表页设置缓存,不同的页面设置不同的缓存,但是由于开始没有安装ngx_cache_purge这个模块,现 ...

  10. nginx各版本全自动编译安装脚本

    #!/bin/bash #作者:星云法师(头条号:西西图图---专注美食领域的研究) #环境:centos7,如果是其它的系统可以相应做调整.#--------选择安装方式,网络晚装还是本地安装--- ...

随机推荐

  1. PAT——1072. 开学寄语(20)

    下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其QQ,封其电脑,夺其手机,收其ipad,断其wifi,使其百无聊赖,然后,净面.理发.整衣,然后思过.读书.锻炼.明智.开悟.精进 ...

  2. 多线程系列 - 基础篇01 - 线程基本概念 & 线程优先级 & 守护线程 60%

    1.什么是线程 将线程理解为轻量级进程,它与进程的最大的区别是: 多个线程共享一个进程资源: 对于OS的许多资源的分配和管理(如内存)通常都是进程级别的,线程只是os调度的最小单位: 相对于进程来说更 ...

  3. ZooKeeper系列(2)--基于ZooKeeper实现简单的配置中心

    ZooKeeper节点的类型分为以下几类:  1. 持久节点:节点创建后就一直存在,直到有删除操作来主动删除该节点 2. 临时节点:临时节点的生命周期和创建该节点的客户端会话绑定,即如果客户端会话失效 ...

  4. DataGuard相关视图

    1.v$database SELECT name,open_mode,database_role,protection_mode,protection_level FROM v$database; 其 ...

  5. Field userService in com.wuji.controller.UserController required a bean of type 'com.wuji.service.UserService' that could not be found

    Field userService in com.wuji.controller.UserController required a bean of type 'com.wuji.service.Us ...

  6. C++构造函数及成员变量

    class MyClass { public: int m_age; float m_hight; MyClass() { } ~MyClass() { } MyClass(int age, floa ...

  7. Windows 安装 MySQL 8.0.11

    下载并解压 从官方网站下载最新安装包 解压到目标安装目录 新建配置文件 在安装目录新建my.ini文件 添加如下内容(需修改为自己的配置) #----------------------------- ...

  8. 【DB2数据库在windows平台上的安装】

  9. Hadoop(二)CentOS7.5搭建Hadoop2.7.6完全分布式集群

    一 完全分布式集群(单点) Hadoop官方地址:http://hadoop.apache.org/ 1  准备3台客户机 1.1防火墙,静态IP,主机名 关闭防火墙,设置静态IP,主机名此处略,参考 ...

  10. python3使用bencode库实现BT种子生成磁力链接

    python3 需要使用 pip install py3-bencode安装py3-bencode库. pip install py3-bencode 这里使用当前目录下的 1.torrent 文件转 ...