大型网站分布式架构(六)—— Nginx的安装

本文详细介绍了如何从源码编译安装Nginx,包括所需依赖库的安装,如PCRE、zlib和openssl,以及常见错误的解决方法。同时,展示了配置过程和启动Nginx的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我们可以使用Nginx做什么:

  • web服务器
  • 负载均衡和反向代理

编译Nginx所需依赖:

依赖功用
pcre解决C语言中使用正则表达式的问题,rewrite模块需要 pcre 库
zlib通用的压缩库,gzip模块需要 zlib 库
openssl提供了丰富的加密解密的相关功能,ssl 功能需要openssl库
perlopenssl的编译需要perl
gccnginx的编译需要gcc


 

 

 

 

 

 

安装依赖
如果主机上没有以上依赖可以执行以下命令:

yum -y install gcc perl zlib pcre-devel openssl openssl-devel


获得Nginx安装包

[root@centos6-1 ~]# cd /export/servers/
[root@centos6-1 servers]# wget http://nginx.org/download/nginx-1.14.0.tar.gz



###解压安装包

[root@centos6-1 servers]# tar -zvxf nginx-1.14.0.tar.gz



编译安装
执行configure

[root@centos6-1 servers]# cd nginx-1.14.0
[root@centos6-1 nginx-1.14.0]# ./configure



博主报了以下错误

./configure: error: the HTTP rewrite module requires the PCRE library.



博主主机缺少PCRE依赖,现在安装

[root@centos6-1 nginx-1.14.0]# yum install pcre-devel



再执行configure,结果如下

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/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"


编译安装

[root@centos6-1 nginx-1.14.0]# make & make install



启动Nginx
 

默认安装路径为:/usr/logcal/nginx

[root@centos6-1 ~]# cd /usr/local/
[root@centos6-1 local]# ll
total 44
drwxr-xr-x. 2 root root 4096 Jul  3 21:56 bin
drwxr-xr-x. 2 root root 4096 Sep 23  2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23  2011 games
drwxr-xr-x. 3 root root 4096 Jul  3 21:56 include
drwxr-xr-x. 3 root root 4096 Jul  3 21:56 lib
drwxr-xr-x. 2 root root 4096 Sep 23  2011 lib64
drwxr-xr-x. 2 root root 4096 Sep 23  2011 libexec
drwxr-xr-x. 6 root root 4096 Aug 26 17:01 nginx
drwxr-xr-x. 2 root root 4096 Sep 23  2011 sbin
drwxr-xr-x. 5 root root 4096 Jun 26 22:25 share
drwxr-xr-x. 2 root root 4096 Jul  8 13:33 src
[root@centos6-1 local]# cd nginx/
[root@centos6-1 nginx]# ll
total 16
drwxr-xr-x. 2 root root 4096 Aug 26 17:01 conf
drwxr-xr-x. 2 root root 4096 Aug 26 17:01 html
drwxr-xr-x. 2 root root 4096 Aug 26 17:01 logs
drwxr-xr-x. 2 root root 4096 Aug 26 17:01 sbin
[root@centos6-1 nginx]# cd sbin/
[root@centos6-1 sbin]# ll
total 3596
-rwxr-xr-x. 1 root root 3679027 Aug 26 17:01 nginx
[root@centos6-1 sbin]# ./nginx 
[root@centos6-1 sbin]# ps -ef|grep nginx
root     101575      1  0 17:04 ?        00:00:00 nginx: master process ./nginx
nobody   101576 101575  0 17:04 ?        00:00:00 nginx: worker process
root     101578  96782  0 17:04 pts/1    00:00:00 grep nginx



可以看到nginx已经启动了,一个master进程,一个worker进程

web访问

è¿éåå¾çæè¿°
总结
nginx已经安装成功。除了通过源码编译安装,还可以通过其他方式安装,但是源码编译可以安装最新版的nginx。在安装过程中会出现一些bug,只需要根据错误提示解决即可。当然博主这里只是介绍了最简单暴力的默认编译安装方式,如果想了解Nginx的编译安装的其他配置细节可以进入Nginx官网获取相关信息。博主后面将使用Nginx与Tomcat集成,优化web的业务处理。
--------------------- 
作者:枣面包 
来源:优快云 
原文:https://blog.youkuaiyun.com/weixin_37490221/article/details/82078185 
版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值