大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
# 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;
}
}
}
域名解析
常用解析多租户解析Nginx虚拟主机域名配置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;
}
}
}
ServerName匹配规则配合二级域名
完整匹配通配符匹配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 httpds{
server 192.168.102.80;
server 192.168.103.80;
}
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上
两者等价
URLRewrite伪静态配置访问: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
}
}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧