nginx基础概述

为什么选择nginx

    nginx非常轻量

    互联网公司都选择nginx

  1. nginx技术成熟,具备的功能时企业最常用使用而且最需要的
  2. 适合当前主流架构趋势,微服务、云架构、中间层
  3. 统一技术栈,降低维护成本,降低技术更新成本

    nginx采用Epool网络模型,Apache采用Select模型

        Select:当用户发起一次请求,select模型就会进行一次遍历扫描,从而导致性能低下

        Epool:当用户发起请求,epool模型会直接进行处理,效率高效,并无连接限制

nginx安装:

    yum 安装

    [root@web01 ~]# vim /etc/yum.repos.d/nginx.repo

    [nginx]

    name=nginx repo

    baseurl=http://nginx.org/packages/centos/7/$basearch/

    gpgcheck=0

    enabled=1

    [root@web01 ~]# yum install nginx -y

    编译安装

    [root@web01 ~]# wget http://nginx.org/download/nginx-1.14.2.tar.gz

    [root@web01 ~]# tar xf nginx-1.14.2.tar.gz

    [root@web01 ~]# cd nginx-1.14.2/

    [root@web01 nginx-1.14.2]# ./configure 【nginx -V里的参数】

    [root@web01 nginx-1.14.2]# make && make install

/etc/nginx/mime.types    nginx类型映射关系表文件

/etc/nginx/nginx.conf    ngixn主配置文件

启动

    systemctl start nginx && systemctl enable nginx

 

nginx配置文件

[root@web01 ~]# 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;    #服务端默认返回给用户的文件

        }

    }

猜你喜欢

转载自www.cnblogs.com/yexiuer/p/10804565.html