博客
关于我
nginx介绍安装
阅读量:683 次
发布时间:2019-03-17

本文共 1592 字,大约阅读时间需要 5 分钟。

Nginx简介

Apache仍然是占用率最高的Web服务器,市场占有率约为50%。了解它的优势:支持静态资源服务器且开源,模块丰富,技术支持成熟。

Nginx则由俄罗斯开发,是一款高性能的HTTP和反向代理服务器。其优势在于:支持5万级别的高并发连接, 系统资源消耗低,稳定性强。目前市场占有率已达33%,且发展势头强劲。选择Nginx的理由简单:高并发支持、成本低、可免费使用,并支持商业用途。

Nginx在系统架构中的作用清晰:作为网关入口,mainly负责路由、负载均衡和静态资源服务。具体来看:

  • 路由功能:根据域名或路径选择后台服务器,适用于微服务架构。
  • 负载功能:对后台服务器集群进行智能分载,应对高并发高可用需求。
  • 静态服务功能:作为静态资源服务器,性能远超Tomcat,适用于MVVM模式下的文件读取。
  • Nginx的工作模式分为正向代理和反向代理。正向代理是客户端请求中介,代为代理事务;反向代理是服务器-end向前发出的服务代理。两者的共同点是加速流量处理。

    Nginx安装方法有三种:

    1. 源码编译安装
    步骤如下:

    • 安装依赖软件:yum -y install autoconf automake make gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
    • 使用wget获取源码:wget nginx-1.9.15.tar.gz
    • 解包并配置:cd nginx-1.9.15 && ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
    • 编译并安装:make && make install
    • 启动:nginx -c /usr/local/nginx/nginx.conf

    2. Yum安装方法(CentOS6)

    • 扩展源:yum install epel-release -y
    • 直接安装:yum install nginx -y
      安装完成后,配置目录结构为:/etc/nginx, 再打开 /usr/local/nginx/conf/nginx.conf 进行配置。

    启动或停止命令为:

    • 开始:nginx -c /usr/local/nginx/nginx.conf
    • 停止:nginx -s stop
    • 退出:nginx -s quit
    • 重新加载:nginx -s reload
      默认情况下,执行命令时可省略配置选项,系统会自动读取默认配置文件。

    Nginx的工作模型分为主进程(master)和多个工作进程(worker)。主进程负责套接字绑定、配置管理;工作进程负责处理客户端连接及任务执行。为了性能,最好将工作进程设置为非特权用户运行。

    Nginx配置文件结构以nginx.conf为中心,采用模块化设计,便于扩展。其主要包括:

    • 全局配置项:userworker_processeserror_log等。
    • HTTP服务器模块:http,设置默认类型、日志格式、ssl模块等。
    • 虚拟服务器段server:指定监听地址、端口、域名及请求路径。
      -Location匹配:定义路由规则,支持静态资源及其错误页面配置。

    通过Nginx日志可以追踪客户端行为和服务器状态。配置access_log并指定路径,可自定义日志格式,打印信息如$remote_addr$request等。 LogManager接口支持灵活配置,支持日志切割和归档管理。

    日志切割可编写脚本实现,生成基于时间戳的日志文件并归档。同时,配置rsyslog和crond后,可实现定时日志清理和信息收集。

    以上均为对Nginx的系统性介绍,实践中可根据具体需求调整配置选项,充分发挥其性能优势。

    转载地址:http://cpkhz.baihongyu.com/

    你可能感兴趣的文章
    No 'Access-Control-Allow-Origin' header is present on the requested resource.
    查看>>
    NO 157 去掉禅道访问地址中的zentao
    查看>>
    no available service ‘default‘ found, please make sure registry config corre seata
    查看>>
    No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
    查看>>
    no connection could be made because the target machine actively refused it.问题解决
    查看>>
    No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
    查看>>
    No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
    查看>>
    No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
    查看>>
    No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
    查看>>
    No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
    查看>>
    No module named 'crispy_forms'等使用pycharm开发
    查看>>
    No module named cv2
    查看>>
    No module named tensorboard.main在安装tensorboardX的时候遇到的问题
    查看>>
    No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
    查看>>
    No new migrations found. Your system is up-to-date.
    查看>>
    No qualifying bean of type XXX found for dependency XXX.
    查看>>
    No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
    查看>>
    No resource identifier found for attribute 'srcCompat' in package的解决办法
    查看>>
    no session found for current thread
    查看>>
    No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>