Nginx介绍与安装
1.介绍
Nginx是一个开源的高性能的HTTP中间件
2.应用场景
静态文件处理
反向代理
负载均衡
缓存
安全防护
访问控制
3.安装
配置yum源
[root@localhost ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=http://nginx.org/keys/nginx_signing.key
安装nginx
yum install nginx -y
nginx安装目录
Nginx主配置⽂文件
/etc/nginx
/etc/nginx/nginx.conf
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
Cgi、Fastcgi、Uwcgi配置⽂文件
/etc/nginx/fastcgi_params
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
http协议的Content-Type与扩展名
/etc/nginx/mime.types
nginx常用模块
ngx_http_core_module
包含⼀一些核⼼心的http参数配置,对应Nginx的配置区块部分
ngx_http_access_module
访问控制模块,⽤用来控制⽹网站⽤用户对Nginx的访问
ngx_http_gzip_module
压缩模块,对Nginx返回的数据压缩,属于性能优化模块
ngx_http_fastcgi_module
fastci模块,和动态应⽤用相关的模块,例例如PHP
ngx_http_proxy_module
proxy代理理模块
ngx_http_upstream_modul e
负载均衡模块,可以实现⽹网站的负载均衡功能及节点的健康 检查。
ngx_http_rewrite_module
URL地址重写模块
ngx_http_limit_conn_modu le
限制⽤用户并发连接数及请求数模块
ngx_http_limit_req_module
限制Nginx request processing rate根据定义的key
ngx_http_log_module
访问⽇日志模块,以指定的格式记录Nginx客户访问⽇日志等信息
ngx_http_auth_basic_mod ule
Web认证模块,设置Web⽤用户通过账号密码访问Nginx
nginx_http_ssl_module
ssl模块,⽤用于加密的http连接,如http
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配置