Nginx笔记系列(1)——Nignx的安装部署 原

Nginx百科

服务器(软件)你能一口气说出几个?从当年“蹒跚学步”学java时开始用 Tomcat,到“PHP是最好的语言”那帮家伙的LAMP中A——Apache,从sun当年不温不火弄出的glassfish,到微软的独苗IIS。但是当“毛子”(没有贬义,其实毛子的科技我还是很仰视的)弄出了个Nginx,似乎有了当年卡巴斯基拍扁瑞星的那种给国人的震撼。尤其是这些年,Nginx似乎成了高性能、高并发等标签的开源服务器的代名词。

本系列就从一个Nginx小白的视角介绍Nginx的种种。

 

什么是Nginx?

  1. Nginx是一种服务器软件,可以—— 发布网络应用程序

  2. Nginx是一个高性能的http和反向代理服务器

    反向代理(Reverse Proxy)是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。

  3. Nginx可以作为一个邮件服务器——代理邮件服务器,实现收发邮件。

  4. Nginx支持负载均衡(借助反向代理实现)。可以利用Nginx服务器作为分发用户请求到各个服务器的中间桥梁,而不实际处理用户的请求。

 

 

与其他服务器的比较:

Apache不支持高并发,而Nginx支持处理百万级的TCP连接,10万以上的并发连接。

Tomcat是面向Java的重服务器,而Nginx是一个轻量级的服务器。(但是Nginx可以和Tomcat联合部署,由Nginx来负责转发Java Web相关的请求给Tomcat,相关配置请关注本系列的后续文章)

Nginx跨平台,再见,IIS! :)

 

Nginx的优缺点:

优点:可以实现高并发、部署简单、内存消耗少、成本低

缺点:rewrite功能不够强,模块没有Apache的多

 

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

安装Nginx

长话短说,一共以下几个步骤:

1)下载stable版本的Nginx源码包,本文用的是nginx-1.8.1.tar.gz,解压。

2)运行nginx-1.8.1.tar.gz/里的configure

3)如果运行./configure出错,按照错误提示,栈装nignx依赖的软件包:gcc、g++,pcre、pcre-devel,zlib、zlib-devel

4)make编译

5)make install

我在我的Fedora系统上的安装过程如下:

第一步,解压

[neil@neilhost Downloads]$ cp nginx-1.8.1.tar.gz ~/Documents/
[neil@neilhost Downloads]$ cd ~/Documents/
[neil@neilhost Documents]$ ll
总用量 832
drwxr-xr-x. 5 neil neil   4096 4月  22 2015 log
drwxr-xr-x. 4 neil neil   4096 2月  29 20:17 MyCraft
-rw-r-----. 1 neil neil 833473 3月   3 11:02 nginx-1.8.1.tar.gz
drwxr-xr-x. 5 neil neil   4096 5月  23 2015 ProgramAPP
drwxr-xr-x. 3 neil neil   4096 6月   5 2015 workspace-sts-3.6.4.RELEASE
[neil@neilhost Documents]$ tar -zxvf nginx-1.8.1.tar.gz 
nginx-1.8.1/
nginx-1.8.1/auto/
nginx-1.8.1/conf/
nginx-1.8.1/contrib/
nginx-1.8.1/src/
nginx-1.8.1/configure
***这里很多很多,此处掠去XXXX个字。——解压完毕


[neil@neilhost Documents]$ ll
总用量 836
drwxr-xr-x. 5 neil neil   4096 4月  22 2015 log
drwxr-xr-x. 4 neil neil   4096 2月  29 20:17 MyCraft
drwxr-xr-x. 8 neil neil   4096 1月  26 22:39 nginx-1.8.1
-rw-r-----. 1 neil neil 833473 3月   3 11:02 nginx-1.8.1.tar.gz
drwxr-xr-x. 5 neil neil   4096 5月  23 2015 ProgramAPP
drwxr-xr-x. 3 neil neil   4096 6月   5 2015 workspace-sts-3.6.4.RELEASE
[neil@neilhost Documents]$ cd nginx-1.8.1/
[neil@neilhost nginx-1.8.1]$ ll
总用量 660
drwxr-xr-x. 6 neil neil   4096 3月   3 11:03 auto
-rw-r--r--. 1 neil neil 251319 1月  26 22:39 CHANGES
-rw-r--r--. 1 neil neil 383019 1月  26 22:39 CHANGES.ru
drwxr-xr-x. 2 neil neil   4096 3月   3 11:03 conf
-rwxr-xr-x. 1 neil neil   2478 1月  26 22:39 configure
drwxr-xr-x. 4 neil neil   4096 3月   3 11:03 contrib
drwxr-xr-x. 2 neil neil   4096 3月   3 11:03 html
-rw-r--r--. 1 neil neil   1397 1月  26 22:39 LICENSE
drwxr-xr-x. 2 neil neil   4096 3月   3 11:03 man
-rw-r--r--. 1 neil neil     49 1月  26 22:39 README
drwxr-xr-x. 8 neil neil   4096 3月   3 11:03 src

第二步,运行configure。

[neil@neilhost nginx-1.8.1]$ ./configure
checking for OS
 + Linux 3.17.4-301.fc21.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.9.2 20150212 (Red Hat 4.9.2-6) (GCC) 
checking for gcc -pipe switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for EPOLLRDHUP ... found
checking for O_PATH ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for nobody group ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for SO_ACCEPTFILTER ... not found
checking for TCP_DEFER_ACCEPT ... found
checking for TCP_KEEPIDLE ... found
checking for TCP_FASTOPEN ... found
checking for TCP_INFO ... found
checking for accept4() ... found
checking for eventfd() ... found
checking for int size ... 4 bytes
checking for long size ... 8 bytes
checking for long long size ... 8 bytes
checking for void * size ... 8 bytes
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system byte ordering ... little endian
checking for size_t size ... 8 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 8 bytes
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for sys_nerr ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for POSIX semaphores ... not found
checking for POSIX semaphores in libpthread ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
checking for sysconf(_SC_NPROCESSORS_ONLN) ... found
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

看吧,出错了,原因是我的电脑没有装过pcre-devel的库,不过pcre有。这里首先安装pcre-devel,注意,无论pcre或pcre-devel都要是小写字母,虽然这里的提示貌似是大写的。(还有,如果你的系统没有安装过gcc和g++,这里应该也会提醒,不过我的系统已经安装了,所以直接提醒的是pcre)

[neil@neilhost nginx-1.8.1]$ sudo yum install pcre-devel
已加载插件:langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 pcre-devel.x86_64.0.8.35-14.fc21 将被 安装
--> 正在处理依赖关系 pcre(x86-64) = 8.35-14.fc21,它被软件包 pcre-devel-8.35-14.fc21.x86_64 需要
--> 正在检查事务
---> 软件包 pcre.i686.0.8.35-8.fc21 将被 升级
---> 软件包 pcre.x86_64.0.8.35-8.fc21 将被 升级
---> 软件包 pcre.i686.0.8.35-14.fc21 将被 更新
---> 软件包 pcre.x86_64.0.8.35-14.fc21 将被 更新
--> 解决依赖关系完成

依赖关系解决

======================================================================================================================================================
 Package                              架构                             版本                                   源                                 大小
======================================================================================================================================================
正在安装:
 pcre-devel                           x86_64                           8.35-14.fc21                           updates                           537 k
为依赖而更新:
 pcre                                 i686                             8.35-14.fc21                           updates                           487 k
 pcre                                 x86_64                           8.35-14.fc21                           updates                           480 k

事务概要
======================================================================================================================================================
安装  1 软件包
升级           ( 2 依赖软件包)

总计:1.5 M
总下载量:537 k
Is this ok [y/d/N]: y
Downloading packages:
pcre-devel-8.35-14.fc21.x86_64.rpm                                                                                             | 537 kB  00:00:02     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
警告:RPM 数据库已被非 yum 程序修改。
  正在更新    : pcre-8.35-14.fc21.x86_64                                                                                                          1/5 
  正在安装    : pcre-devel-8.35-14.fc21.x86_64                                                                                                    2/5 
  正在更新    : pcre-8.35-14.fc21.i686                                                                                                            3/5 
  清理        : pcre-8.35-8.fc21                                                                                                                  4/5 
  清理        : pcre-8.35-8.fc21                                                                                                                  5/5 
  验证中      : pcre-deve
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值