Nginx

假如想象 提交于 2020-02-09 17:31:44

1.Nginx:
是一款代理服务器,可以左反向代理,可以同时支撑五万以上并发量,占内存和CUP比较少,所以说大部分公司都用Nginx
2.Nginx作用:
1.Http:服务器(反向代理)
2.虚拟主机,静态服务器
3.支持负载均衡,权重等等机制
4.集群
5.动态分离
6.静态资源:Nginx服务器管理静态资源,将静态资源放入nginx中,然后进行访问
3.安全架构:
1.nginx:可以做反向代理,不暴露真实的IP地址
2.使用HTTPS防止抓包分析HTTP请求
3.搭建企业黑名单白名单(防盗链)
4.模拟请求(csrf),xxs攻击,sql注入
5.ddos流量攻击,多个ip频繁发送请求,占用网络的带宽
6.csrf表单重复提交,攻击的是业务
4.反向代理服务器:
接收暴露给外界一个公网地址,外界通过工网地址访问nginx,映射内外服务器地址
Nginx服务器,lvs(中国人写的),F5通过硬件解决负载均衡,HaProxy
5.Nginx采用Http协议进行访问。默认端口为80
目录作用:
conf:配置文件目录
contrib:依赖信息目录,不关注
docs:文件目录
html:存放的接收静态资源
kogs:日志
temp:临时文件目录
nginx.exe文件nginx启动文件

在这里插入图片描述

nginx.conf配置文件

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;
        #}
    }

8.Nginx集群负载均衡
默认采用轮训机制,配置方式如下:

upstream backserver { server localhost:8080; server localhost:8081; }
server {
listen       80;
server_name  www.wdksoft.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
	proxy_pass http://backserver;
	index index.jsp index.htm;
}
}

权重比例配置

upstream backserver { 
server localhost:8080 weight=2; 
server localhost:8081 weight=1; 
}

IP固定绑定,只能访问其中绑定的服务器
upstream backserver { 
ip_hash;
server localhost:8080; 
server localhost:8081;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!