为什么选择 nginx
????nginx 非常轻量
???? 互联网公司都选择 nginx
nginx 技术成熟, 具备的功能时企业最常用使用而且最需要的
适合当前主流架构趋势, 微服务, 云架构, 中间层
统一技术栈, 降低维护成本, 降低技术更新成本
????nginx 采用 Epool 网络模型, Apache 采用 Select 模型
????????Select: 当用户发起一次请求, select 模型就会进行一次遍历扫描, 从而导致性能低下
????????Epool: 当用户发起请求, epool 模型会直接进行处理, 效率高效, 并无连接限制
nginx 安装:
????yum 安装
- ????[[email protected] ~]# VIM /etc/yum.repos.d/nginx.repo
- ????[nginx]
- ????name=nginx repo
- ????baseurl=http://nginx.org/packages/centos/7/$basearch/
- ????gpgcheck=0
- ????enabled=1
- ????[[email protected] ~]# yum install nginx -y
???? 编译安装
- ????[[email protected] ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz
- ????[[email protected] ~]# tar xf nginx-1.14.2.tar.gz
- ????[[email protected] ~]# cd nginx-1.14.2/
- ????[[email protected] nginx-1.14.2]# ./configure [nginx -V 里的参数]
- ????[[email protected] nginx-1.14.2]# make && make install
/etc/nginx/mime.types????nginx 类型映射关系表文件
/etc/nginx/nginx.conf????ngixn 主配置文件
启动
- ????systemctl start nginx && systemctl enable nginx
- ?
nginx 配置文件
[[email protected] ~]# cat /etc/nginx/nginx.conf
--------------- 核心模块
- user nginx;????????????????????????????????????#nginx 进程运行的用户
- worker_processes 1;????????????????????????????#nginx 工作的进程数量
- error_log /var/log/nginx/error.log warn;????????#nginx 的错误日志 [警告及其警告以上的都记录]
- pid /var/run/nginx.pid;????????????????????#nginx 进程运行后的进程 id
- --------------
- ?
--------------- 事件模块
- events {
- worker_connections 1024;????????????????????# 一个 work 进程的最大连接数
- ????use epool;????????????????????????????????????# 使用 epool 网络模型
- }
- --------------
- ?
---------------http 核心层模块
- http {
- include /etc/nginx/mime.types;????????????????# 包含资源类型文件
- default_type application/octet-stream;????????????????# 默认以下载方式传输给浏览器 (前提是该资源在 mime.types 中无法找到)
- ?
???? 日志格式定义
- log_format main '$remote_addr - $remote_user [$time_local]"$request"''$status $body_bytes_sent "$http_referer" ''"$http_user_agent""$http_x_forwarded_for"';
- ?
- access_log /var/log/nginx/access.log main;????????# 访问日志
- ?
- sendfile on;????????
- #tcp_nopush on;
- keepalive_timeout 65;????????# 长连接超时时间
- #gzip on;????????????????????# 是否开启压缩功能
- ????
- ????include /etc/nginx/conf.d/*.conf;????????# 包含哪个目录下面的 *.conf 文件
- ????
????server { 定义一个网站
- ????????listen 80;????????????# 监听端口
- ????????server_name localhost;????????# 域名
- ?
- ????????#charset koi8-r;????????????# 字符集
- ?
- ????????location / {
- ???? ????????????# 位置
- ????????????root /usr/share/nginx/html;????# 代码的主文件位置
- ????????????index index.HTML index.htm;????# 服务端默认返回给用户的文件
- ????????
- }
- ????????location /test {
- ???? ????????????# 位置
- ????????????root /code/test/123/;????# 代码的主文件位置
- ????????????index index.HTML index.htm;????# 服务端默认返回给用户的文件
- ????????
- }
- ????}
来源: http://www.bubuko.com/infodetail-3045004.html