Open minggen opened 5 years ago
# alias root 区别 alias不加入path root加入path
# location
# =:精确匹配(必须全部相等)
# ~:大小写敏感
# ~*:忽略大小写
# ^~:只需匹配uri部分
# @:内部服务跳转
# 负载均衡
# upstream ${upstream}{
# server 127.0.0.1:8080;
# server 127.0.0.1:9080;
#}
server {
listen ${port}; #端口
server_name ${domain}; #域名
root ${rootpath}; #根目录
access_log ${rootpath}${success_log_path}; #成功日志
error_log ${rootpath}${error_log_path}; #错误日志
#配置静态页面,前端静态页面,精确匹配
location = / {
#root #D:/soft/nginx-1.14.2/html/a.b; #静态path,可以配置绝对路径,也可以配置相对上面的相对路径
index ${index};
}
#配置转发
location / {
# 因为所有的地址都以 / 开头,所以这条规则将匹配到所有请求
# 但是正则和最长字符串会优先匹配
# 一般配置转发
proxy_pass ${api}; # 转发到 upstream 负载均衡
#proxy_set_header X-real-ip $remote_addr;
#proxy_set_header Host $http_host;
#proxy_pass http://127.0.0.1:8080;
#proxy_redirect off;
#proxy_set_header Host $http_host; #传递主机名
#proxy_set_header X-Forwarded-Host $http_host; #传递真实主机名
#proxy_set_header X-Real-IP $remote_addr; #传递用户IP
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #传递用户真实IP
#proxy_set_header X-Forwarded-Proto $scheme; #传递协议http/https
#proxy_set_header Upgrade $http_upgrade; #反向代理websocket
#proxy_set_header Connection $connection_upgrade; #反向代理websocket
#proxy_set_header Connection "Upgrade";
#proxy_http_version 1.1; #传递协议版本号
}
location ^~ /images/ {
# 匹配任何以 /images/ 开头的地址,匹配符合以后,停止往下搜索正则,采用这一条。
#[ configuration D ]
}
# 静态资源
location ~* \.(gif|jpg|jpeg|png|css|js|ico)$ {
#root /webroot/res/;
# 匹配所有以 gif,jpg或jpeg 结尾的请求
# 然而,所有请求 /images/ 下的图片会被 config D 处理,因为 ^~ 到达不了这一条正则
#[ configuration E ]
# expires 30d; 时间
}
#配置静态目录浏览
location /${dirpath} {
alias ${rootpath}${dirpath} ; #静态path,
autoindex on; #on 开启目录浏览功能 默认关闭
#autoindex_localtime on; #之类的参数写这里
}
}