1.什么是nginx,nginx?
优点 Nginx安装非常的简单,配置文件非常简洁(还能够支持per语法),Bugs非常少的服务器:Nginx启动特别容易,并且几乎可以做到7*24不间断运行,即使运行数个月也不需要重新启动。你还能够在不间断服务的情况下进行软件版本的升级。
nginx可以作为web服务器,但更多的时候,我们把它作为网关 为啥?因为网关有的功能,它都可以做到,如下....而且优点上面都介绍清楚了.
Nginx提供的负载均衡策略有2种:内置策略和扩展策略。 内置策略为轮询,加权轮询,Ip hash。 扩展策略,就天马行空,只有你想不到的没有他做不到的啦,你可以参照所有的负载均衡算法,给他一一找出来做下实现。
上3个图,理解这三种负载均衡算法的实现
Ip hash算法,对客户端请求的ip进行hash操作,然后根据hash结果将同一个客户端ip的请求分发给同一台服务器进行处理,可以解决session不共享的问题。
及其适合微服务项目,大量端口需要路由
参考https://www.cnblogs.com/xxoome/p/5866475.html 下载解压好了,这里看以下nginx里有啥玩意
首先进入conf配置咱们的nginx
vi进入后编辑,这里以注释的方式解读一下配置
#user nobody;
worker_processes 1; //工作进程数(处理请求的进程)(通常不大于服务器核数)
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;//工作连接数-线程数
}
http { //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 {//一个server就是一个代理
listen 80;//监听的服务端口
server_name localhost;//这个主机的都默认转到80端口
#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;
#}
}
菜鸟教程Nginx nginx中文文档 Nginx 配置文件详解 运行和控制Nginx nginx域名配置 前端项目发布到nginxweb服务器