1.nginx简介:
nginx是企业高可用的web服务器,nginx也可用来做反向代理服务器器,具有高并发,占用资源少,功能丰富,也可以作为简单的负载均衡。
nginx在企业中的功能:
web服务软件反向代理服务器
前端数据缓存服务器
2.为什么nginx性能高于apache
当查询事物时,nginx使用了epoll模型,apache使用的是传统的select,epoll类似会将查询事物标上序号,方便下次查询。传统的select查询,需要将事物逐一查询。
3.安装nginx
安装nginx需要配置epel源
cd /etc/yum.repos.d/
vim epel.repo
[epel]
name=epel
baseurl=https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
yum install -y nginx
4.nginx配置文件
nginx配置文件:/etc/nginx/nginx.conf
nginx额外配置文件:/etc/nginx/conf.d/*.conf
nginx配置文件简单说明
[root@manage ~]# more /etc/nginx/conf.d/vhosts.conf
server { server区块
listen 80; 服务器端口
server_name bbs.yunjisuan.com; 服务器域名
location / { location区块
root /usr/share/nginx/html/bbs; 定义首页文件存放的站点目录
index index.html index.htm; 定义首页文件去寻找呢些
}
}
5.nginx的一些常用功能:
nginx location:
location:根据不同的url来执行不同的应用
location语法:
location 匹配标识 匹配的网站地址 {匹配到后执行的片段}
=/
^~/images/
~*\.(gif|jpg)
/adc/
/
nginx rewrite:
实现url重写
rewrite语法:
rewrite regexp(正则匹配) 重写的网址[flag]
location / {
root html;
index index.html ;
rewrite ^/xxxxx/(.*) /bbs/$1 last ;
}