nginx简单介绍

2019-04-15  本文已影响0人  繁花似锦之流年似水

1、功能

功能1:负载均衡:指的是应用不用的调度算法,将请求转发给不同的服务器。它主要解决并发的时候请求数量多多场景,能提高服务器性能,解决网络拥堵的问题

功能2:反向代理,代理的是服务端【正向代理代理的是客户端】。当网站服务端访问量太多的时候,我们需要增加服务器。我们在用户和真实服务器之间增加一个代理服务器。用户请求由代理服务器转发给真实的应用服务器。这块的代理服务器我们用的就是nginx,它能处理50000个链接(包括活跃链接和非活跃链接)。而diango处理的并发量是2000

功能3:可以作为静态资源服务器:存放资源js,ccs,图片等。通常我们访问页面胡时候需要加载静态资源和动态资源。动态资源指的是需要在通过业务服务器在后台查询数据库,静态资源指的椒那些图片、css文件等。中小网站我们可以把静态文件放到nginx服务器上,提高网站响应速度。动态资源则继续通过nginx转发访问业务服务器

niginx的优点:

跨平台,配置简单,可移植

内存消耗小

非阻塞高并发连接

内置的健康检查:出现服务器宕机时,会做健康检查,将请求转发到正常的节点

master/worker结构:一个master进程,生成一个或者多个worker进程

事件驱动:通信机制采用epoll模型

nginx的高可用

大型网站采用主从部署,部署两个niginx服务器,当主节点挂掉或者主节点的nginx进程或者keepalived挂掉后,从节点上的keepalived会检测到并会接管原先master节点【主节点】的网络功能,这种方式来实现Nginx的高可用。

【注】keepalived用来保证集群高可用,防止单点故障。对外体现出来的效果是,两台niginx服务器设置一个虚拟机IP,通过这个虚拟IP可以访问到两个服务器,这两个服务器一个是主节点,一个是从节点。当检测到主节点故障。从升主,主变从

niginx性能问题

2、nginx的配置文件详解

#user nobody;        定义nginx运行时候的用户和用户组

worker_processes  1;      定义nginx工作的时候拉起多少workers,一般与CPU数量一致

#error_log  logs/error.log;   

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;         nginx对应的进程ID

events {

    worker_connections  1024;   一个nginx进程可以打开的最大文件描述符数目

}

http {

    include      mime.types;  定义了文件后缀名类型

    default_type  application/octet-stream;   二进制,代表不识别的文件类型默认为二进制

    #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  logs/access.log  main;  定义日志路径和采用的格式

    sendfile        on;      直接往外转发图片,不经过用户空间

    #tcp_nopush    on;

    #keepalive_timeout  0;

    keepalive_timeout  65;

    #gzip  on;

    server {

        listen      80;

        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

            root  html;

            index  index.html index.htm;

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html

        #

        error_page  500 502 503 504  /50x.html;

        location = /50x.html {

            root  html;

        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass  http://127.0.0.1;

        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        #location ~ \.php$ {

        #    root          html;

        #    fastcgi_pass  127.0.0.1:9000;

        #    fastcgi_index  index.php;

        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

        #    include        fastcgi_params;

        #}

        # deny access to .htaccess files, if Apache's document root

        # concurs with nginx's one

        #

        #location ~ /\.ht {

        #    deny  all;

        #}

    }

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

    #server {

    #    listen      8000;

    #    listen      somename:8080;

    #    server_name  somename  alias  another.alias;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

    # HTTPS server

    #

    #server {

    #    listen      443 ssl;

    #    server_name  localhost;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;

    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;

    #    ssl_prefer_server_ciphers  on;

    #    location / {

    #        root  html;

    #        index  index.html index.htm;

    #    }

    #}

}

上一篇 下一篇

猜你喜欢

热点阅读