Nginx入门

常用的Web容器

1.Apache

2.IIS -> 微软

3.GWS -> Google

4.openrestry

5.tengline -> 淘宝基于Nginx开发

Nginx简介

Nginx是⼀个开源且⾼性能、可靠的HTTP中间件、代理服务。
开源: 直接获取源代码
⾼性能: ⽀持海量并发  

Nginx应⽤场景

静态处理 反向代理 负载均衡 资源缓存 安全防护 访问限制 访问认证

Nginx优秀特性

Nginx基于IO多路复⽤

IO多路复⽤的实现⽅式有select、 poll、 Epool

select缺点 1.能够监视⽂件描述符的数量存在最⼤限制 2.线性遍历扫描效率低下

2.epool模型 1.每当FD就绪,采⽤系统的回调函数之间将fd放⼊,效率更⾼。 2.最⼤连接⽆限制

Nginx快速安装

1.安装环境:linux7.4
  • 环境准备


    //确认系统⽹络
    [root@Nginx ~]# ping baidu.com

    //关闭firewalld
    [root@Nginx ~]# systemctl stop firewalld
    [root@Nginx ~]# systemctl disable firewalld

    //临时关闭selinux
    [root@Nginx ~]# setenforce 0

    //初始化基本⽬录
    [root@Nginx ~]# mkdir /soft/{code,logs,package,backup} -p

    //基本安装包
    [root@Nginx ~]# yum install -y gcc gcc-c++ autoconf \
    Nginx快速安装pcre pcre-devel make automake wget httpd-tools vim tree

    //配置Nginx官⽅Yum源
    [root@Nginx ~]# vim /etc/yum.repos.d/nginx.repo
    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/7/$basearch/
    gpgcheck=0
    enabled=1

    //安装Nginx
    [root@Nginx ~]# yum install nginx -y
    //查看Nginx当前版本
    [root@Nginx ~]# nginx -v

Nginx编译安装

./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

Nginx内置变量

 

$uri: 当前请求的uri,不带参数 $request_uri: 请求的uri,带完整参数 $host: http请求报⽂中host⾸部,如果没有则以处理此请求的虚拟主机的主机名代替 $hostname: nginx服务运⾏在主机的主机名 $remote_addr: 客户端IP $remote_port: 客户端端⼝ $remote_user: 使⽤⽤户认证时客户端⽤户输⼊的⽤户名 $request_filename: ⽤户请求中的URI经过本地root或alias转换后映射的本地⽂件路径 $request_method: 请求⽅法, GET POST PUT $server_addr: 服务器地址 $server_name: 服务器名称 $server_port: 服务器端⼝ $server_protocol: 服务器向客户端发送响应时的协议, 如http/1.1 http/1.0 $scheme:在请求中使⽤scheme, http://xxx.com中的http $http_HEADER: 匹配请求报⽂中指定的HEADER $http_host: 匹配请求报⽂中的host⾸部 $document_root: 当前请求映射到的root配置

你可能感兴趣的:(Nginx入门)