001. Nginx场景,优点,组成部分和编译
目录
- 一: Nginx三个重要的使用场景
- 二: Nginx的优点
- 三:Nginx文件的组成部分
- 四:编译Nginx
一: Nginx三个重要的使用场景
- 静态资源服务
- 疑问:为什么需要静态资源服务?
- 答: 在整个的web请求流程中(浏览器—> Nginx ----> Web服务器 ----> 数据库/缓存)有些静态资源, 没必要通过Web服务器再去寻找到这些资源, 比如: HTML, CSSS, JS, 图片等。因此我们可以将这些静态资源, 放在服务器上, 当服务请求到Nginx服务器的时候, 由Nginx服务器直接访问服务器上的资源, 然后立刻返回即可。
- 反向代理服务
- 疑问: 什么是反向代理?
- 答:简言之, 代理多台web服务器, 浏览器对多台Web服务器是无感知的, 只知道将请求转发到代理服务器(Nginx)上即可。
- 反向代理流程:由客户端发起对代理服务器的请求,代理服务器在中间将请求转发给某一个服务器,服务器将结果返回给代理服务器,代理服务器再将结果返回给客户端。
- 疑问:为什么需要反向代理?
- 答:随着业务的不断发展, 应用服务一般都是集群模式的, 因此会带来两个需求。 1: 横向扩容 2: 容灾。横向扩容就需要部署多台服务器, 而请求需要转发到那台服务器呢? 因此就需要Nginx具备负载均衡的能力。 容灾就是指的, 一旦某个业务服务出现问题, Nginx就将原本转发到这个服务器的请求, 转发给其他的服务器。基于这两点需求, Nginx必须具备反向代理业务服务器的功能。
- API服务
- 疑问:为什么需要API服务?
- 答:有些请求, 功能简单, 没必要用业务服务器来实现, 而是直接访问数据库可以查询到。 而且数据库服务无论是稳定性还是并发能力, 都比业务服务器高的多。
二: Nginx的优点
- 高并发, 高性能
- nginx 可以达到数千万的并发能力
- 可扩展性好
- 模块化设计, 有丰富的生态圈
- 高可靠
- 持续运行, 不会挂掉
- 热部署
- 不用停止服务,进行升级。
- BSD许可证
- 开源, 可以对源码进行修改, 并应用到商业软件中
三:Nginx文件的组成部分
- 二进制可执行文件
- 各个模块编译出来的一些文件
- 配置文件
- nginx.conf
- 日志文件
- access.log
- error.log
四:编译Nginx
- 下载Nginx源码并解压
- wget http://nginx.org/download/nginx-1.14.0.tar.gz
- tar -zxvf nginx-1.14.0.tar.gz
- 了解Nginx源码目录结构
drwxr-xr-x 13 kj staff 416B 4 17 2018 .
drwx------+ 24 kj staff 768B 12 31 16:00 ..
-rw-r--r-- 1 kj staff 280K 4 17 2018 CHANGES # 版本特性和bugfix
-rw-r--r-- 1 kj staff 427K 4 17 2018 CHANGES.ru # 俄罗斯版本的
-rw-r--r-- 1 kj staff 1.4K 4 17 2018 LICENSE #
-rw-r--r-- 1 kj staff 49B 4 17 2018 README
drwxr-xr-x 25 kj staff 800B 4 17 2018 auto # 目录中存储:编译cc,依赖lib, 操作系统os, 类型types
drwxr-xr-x 11 kj staff 352B 4 17 2018 conf # 配置案例文件
-rwxr-xr-x 1 kj staff 2.4K 4 17 2018 configure # 编译前的执行脚本文件
drwxr-xr-x 6 kj staff 192B 4 17 2018 contrib # 高亮显示nginx配置
drwxr-xr-x 4 kj staff 128B 4 17 2018 html # 提供了两个标准HTML: index.html和50x.html
drwxr-xr-x 3 kj staff 96B 4 17 2018 man # 帮助文档
drwxr-xr-x 9 kj staff 288B 4 17 2018 src # 源代码
- 高亮显示nginx配置
- cp -r contrib/vim/* ~/.vim/
- 了解configure支持哪些参数?
- ./configure --help
# 第一类:制定输出文件位置, 一般制定前缀即可。--prefix=PATH set installation prefix--sbin-path=PATH set nginx binary pathname--modules-path=PATH set modules path--conf-path=PATH set nginx.conf pathname--error-log-path=PATH set error log pathname--pid-path=PATH set nginx.pid pathname--lock-path=PATH set nginx.lock pathname
# 第二类:默认不会编译到nginx中的, 需要指定下面的参数, 才会编译到nginx模块中。--with-http_ssl_module enable ngx_http_ssl_module--with-http_v2_module enable ngx_http_v2_module--with-http_realip_module enable ngx_http_realip_module--with-http_addition_module enable ngx_http_addition_module--with-http_xslt_module enable ngx_http_xslt_module--with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module--with-http_image_filter_module enable ngx_http_image_filter_module--with-http_image_filter_module=dynamicenable dynamic ngx_http_image_filter_module--with-http_geoip_module enable ngx_http_geoip_module--with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module--with-http_sub_module enable ngx_http_sub_module--with-http_dav_module enable ngx_http_dav_module--with-http_flv_module enable ngx_http_flv_module--with-http_mp4_module enable ngx_http_mp4_module--with-http_gunzip_module enable ngx_http_gunzip_module--with-http_gzip_static_module enable ngx_http_gzip_static_module--with-http_auth_request_module enable ngx_http_auth_request_module--with-http_random_index_module enable ngx_http_random_index_module--with-http_secure_link_module enable ngx_http_secure_link_module--with-http_degradation_module enable ngx_http_degradation_module--with-http_slice_module enable ngx_http_slice_module--with-http_stub_status_module enable ngx_http_stub_status_module
# 第三类:默认会编译到nginx模块中的, 如果指定下面的参数, 则不会编译到nginx中。 --without-http_charset_module disable ngx_http_charset_module--without-http_gzip_module disable ngx_http_gzip_module--without-http_ssi_module disable ngx_http_ssi_module--without-http_userid_module disable ngx_http_userid_module--without-http_access_module disable ngx_http_access_module--without-http_auth_basic_module disable ngx_http_auth_basic_module--without-http_mirror_module disable ngx_http_mirror_module--without-http_autoindex_module disable ngx_http_autoindex_module--without-http_geo_module disable ngx_http_geo_module--without-http_map_module disable ngx_http_map_module--without-http_split_clients_module disable ngx_http_split_clients_module--without-http_referer_module disable ngx_http_referer_module--without-http_rewrite_module disable ngx_http_rewrite_module--without-http_proxy_module disable ngx_http_proxy_module--without-http_fastcgi_module disable ngx_http_fastcgi_module--without-http_uwsgi_module disable ngx_http_uwsgi_module--without-http_scgi_module disable ngx_http_scgi_module--without-http_grpc_module disable ngx_http_grpc_module--without-http_memcached_module disable ngx_http_memcached_module--without-http_limit_conn_module disable ngx_http_limit_conn_module--without-http_limit_req_module disable ngx_http_limit_req_module--without-http_empty_gif_module disable ngx_http_empty_gif_module--without-http_browser_module disable ngx_http_browser_module--without-http_upstream_hash_moduledisable ngx_http_upstream_hash_module--without-http_upstream_ip_hash_moduledisable ngx_http_upstream_ip_hash_module--without-http_upstream_least_conn_moduledisable ngx_http_upstream_least_conn_module--without-http_upstream_keepalive_moduledisable ngx_http_upstream_keepalive_module--without-http_upstream_zone_moduledisable ngx_http_upstream_zone_module
# 第四类:编译过程中一些优化参数: 例如输出debug日志等。--with-cc=PATH set C compiler pathname--with-cpp=PATH set C preprocessor pathname--with-cc-opt=OPTIONS set additional C compiler options--with-ld-opt=OPTIONS set additional linker options--with-cpu-opt=CPU build for the specified CPU, valid values:pentium, pentiumpro, pentium3, pentium4,athlon, opteron, sparc32, sparc64, ppc64--without-pcre disable PCRE library usage--with-pcre force PCRE library usage--with-pcre=DIR set path to PCRE library sources--with-pcre-opt=OPTIONS set additional build options for PCRE--with-pcre-jit build PCRE with JIT compilation support--with-zlib=DIR set path to zlib library sources--with-zlib-opt=OPTIONS set additional build options for zlib--with-zlib-asm=CPU use zlib assembler sources optimizedfor the specified CPU, valid values:pentium, pentiumpro--with-libatomic force libatomic_ops library usage--with-libatomic=DIR set path to libatomic_ops library sources--with-openssl=DIR set path to OpenSSL library sources--with-openssl-opt=OPTIONS set additional build options for OpenSSL--with-debug enable debug logging
执行编译:
- ./configure --prefix=/Users/kj/Desktop/nginx
了解编译后的文件
- 编译完成后回多一个目录:objs
XYSZW00468:objs kj$ tree . ├── autoconf.err ├── ngx_auto_config.h ├── ngx_auto_headers.h └── ngx_modules.c # 这个文件存放着一会安装的时候需要安装哪些模块
- 执行make编译
- 执行make install 进行安装
- 安装成功后, 在自己指定的路径下回多出很多文件, 包括: log等
- 编译完成后回多一个目录:objs
mac 安装与启动nginx:
- 安装: brew install nginx
- 启动:brew services start/restart/stop nginx
- 查看安装相关信息: brew info nginx
001. Nginx场景,优点,组成部分和编译相关推荐
- 安装nginx(官网下载编译安装)
1.官网https://nginx.org/下载对应的nginx包,推荐使用稳定版本 2.上传nginx到centOs7系统(这里使用xshell和xftp,连接到自己本地vm的centOs7中) 3 ...
- 利用Nginx正向代理加速代码编译外网依赖下载速度
一个典型场景: 之前在ci涉及项目代码构建过程中的依赖都需要到国外下载,例如GitHub,谷歌等等,最初的解决方案是在公司国外服务器节点上安装gitlab-runner,并registe ...
- nginx之 nginx-1.9.7 编译安装、理论简介
nginx是一个web网站常用的高性能http和反向代理服务器,其具有较好的并发能力,被网易.百度.腾讯.新浪等网站广泛使用. 一. 理论简介 1.首先弄清楚正向代理和反向代理 正向代理:代理客户端, ...
- centos6.3 nginx php,CentOS 6.3 编译安装Nginx+MySQL+PHP
测试篇 cd /usr/local/nginx/html/ #进入nginx默认网站根目录 rm -rf /usr/local/nginx/html/* #删除默认测试页 vi index.php # ...
- Nginx+Php-fpm+MySQL+Redis源代码编译安装指南
说明:本教程主要包括以下三个部分: 1. 源代码编译安装Nginx 2. 源代码编译安装php以及mysql.redis扩展模块 3. 配置虚拟主机 文中所涉及安装包程序均提供下载链接,欢迎使用 运行 ...
- linux nginx mysql php 5.5.,编译安装Linux + Nginx1.10 + Mysql5.5 + PHP5.6
前言:本教程只编译NMP,依赖文件都用YUM,不编译了,珍爱生命,不要浪费时间! YUM 依赖文件 yum -y install gcc gcc-c++ autoconf cmake libjpeg ...
- linux安装nginx详细步骤和make编译报错问题(保姆级)
目录 1.安装依赖包 2.下载并解压安装包 3.安装nginx 3-1.源码编辑时常见错误解决方法 4.启动nginx服务 4-1.配置nginx.conf 5.重启nginx 6.若想使用外部主机访 ...
- nginx的yum安装和编译安装
一.什么是nginx? nginx是一个做网站服务器的软件,是静态的网站 html 写前端静态页面的语言 python,java,php,go等动态语言,写后端的,就是和数据库进行交互 二.nginx ...
- Nginx服务器优点
Nginx服务器以及其他服务器横向对比 微软的IIS IIS(Internet信息服务)英文Internet Information Server的缩写.它是微软公司主推的服务器,不过必须要服务器是W ...
最新文章
- C语言 · 求矩阵各个元素的和
- 一个简单的第三方CNN自编码matlab工具箱
- 自动化测试之鼠标悬浮操作、双击、鼠标拖拽
- 出现 HTTP 错误 500.19 错误代码 0x800700b7
- 逻辑漏洞小结之SRC篇
- php /usr/lib/libjpeg.so.62,linux PHP的装配
- 7-10 A-B (20 分)
- 阿里影业正式成为阿里集团子公司 俞永福辞任执行董事
- 加速编程效率,你不知道的IDEA功能设置
- GitHub 一周热点速览:手撕 LeetCode 一日 Star 破两千
- eclipse neon php插件,Eclipse Neon安装Tomcat插件
- 匹配滤波器的仿真——原理说明与仿真
- 什么是简单边界点(Simple border points)
- ws2812怎么调亮度_iOS 11 自动亮度调节,居然藏这么深!
- 机器人系统常用仿真软件工具介绍、效果与评价指标(2018年更新)
- CortexM3/M4(3)-指令集
- 爱python,爱学习
- python寻峰算法_python/scipy的寻峰算法
- 英汉对照名言隽语(四)
- 输入现在的日期,输出明天的日期