首页 技术 正文
技术 2022年11月19日
0 收藏 523 点赞 3,000 浏览 5806 个字

一、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.在浏览器中打开,效果如下

Nginx之一:Nginx的编译安装

四、说明

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

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

下一篇: 二维DCT变换
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902