- nginx
- 最小配置解析
- 域名解析
- 常用解析
- 多租户解析
 
- Nginx虚拟主机域名配置
- ServerName匹配规则
- 完整匹配
- 通配符匹配
- 通配符结束匹配
- 正则匹配
 
- 隧道式模型、网关、代理
- 正向代理&反向代理
- 网关
- 隧道式模式
 
- 反向代理
- 反向代理一台服务器
- 反向代理多台服务器
- 负载均衡策略
 
- 动静分离
- URLRewrite伪静态配置
 
- 网关服务器
- Nginx高可用
- 加密
 
# worker 进程数,ngin 有主从之分,worker主要负责工作,使用ps -ef|grep woker 可以看到
worker_processes  1;
# 每个worker的连接数
events {
    worker_connections  1024;
}
http {
# 包含的子配置
    include       mime.types;
# mime.type 配置了各种请求类型,如果无法匹配使用 default_type
    default_type  application/octet-stream;
 
# 数据零拷贝,nginx 把 文件 直接通过linux 返回给客户端
    sendfile        on;
# 连接超时时间
    keepalive_timeout  65;
# vhost
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }   
}


worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  www.lindou.top;
        location / {
            root   /www/www;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       80;
        server_name  vod.lindou.top;
        location / {
            root   /www/vod;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}
配合二级域名
完整匹配通配符匹配server_name vod1.lindou.top vod1.lindou.top;
通配符结束匹配server_name *.lindou.top;
正则匹配server_name vod.lindou.*;
隧道式模型、网关、代理 正向代理&反向代理server_name ~^[0-9]+.lindou.com$;

中转作用
隧道式模式:就是nginx反向代理模式,入口走nginx,出口也走nginx
lvs,DR模式:入口走nginx,出口直接返回到内网网关上
使用 proxy_pass ,下面两行就无用了
server {
	        listen       80;
	        server_name  vod.lindou.top;
	
	
	        location / {
	        	proxy_pass http://www.atguigu.com;
	          #  root   /www/vod;
	          #   index  index.html index.htm;
	        }使用 upstream httpds
- 配置upstream
 与server块同一级别upstream httpds{ 
 server 192.168.102.80;
 server 192.168.103.80;
 }
- 配置server块
 注意名称
server {
	        listen       80;
	        server_name  vod.lindou.top;
	
	
	        location / {
	        	proxy_pass http://httpds;
	          #  root   /www/vod;
	          #   index  index.html index.htm;
	        }
默认轮询
以下了解,生产存在问题
weight权重

down不参与负载均衡
backup备用机(正常不参与负载均衡)
将静态文件放在nginx上

两者等价



访问:http://localhost/test/2.html 会转到 http://localhost/test/index.jsp?pageNum=2
通用配置

使用keepalived配置nginx高可用

主:192.168.10.190
备:192.168.10.191
v:192.168.10.200
- 主、备安装依赖
yum install openssl-devel
yum install keepalived
配置在: /etc/keepalived/keepalived.conf
2. 主配置
主要修改上边这部分
! Configuration File for keepalived
global_defs {
    router_id lb191
}
vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.200
    }
}
- 备配置
 主要修改上边这部分
! Configuration File for keepalived
global_defs {
    router_id lb190
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.10.200
    }
}
- 启动
 保证nginx都启动了
 启动keepalived: systemctl start keepalived
 然后再windows测试使用:ping 主机 -t
 尝试挂掉主nginx


你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
网站名称:nginx基础篇-创新互联
网页链接:http://www.scyingshan.cn/article/ccccse.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 