企业nginx应用实例(功能拆分记录)
一.默认访问协议强制跳转(http--->https)
server {
listen ;
server_name dannylinux.top www.dannylinux.top;
# rewrite ^/(.*) https://$server_name/$1 permanent;
return https://$server_name/$request_uri;
}
server {
listen ;
server_name dannylinux.top www.dannylinux.top;
ssl on;
ssl_certificate /usr/local/nginx/conf/ssl/server.pem;
ssl_certificate_key /usr/local/nginx/conf/ssl/server.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1. TLSv1.;
#启用TLS1.、TLS1.2要求OpenSSL1..1及以上版本,若您的OpenSSL版本低于要求,请使用 ssl_protocols TLSv1;
ssl_ciphers HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
ssl_prefer_server_ciphers on;
location /
{
root /opt/source/dannyweb;
index index.html;
}
}
二.获取用户真实源IP
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Cookie $http_cookie;
client_max_body_size 30m;
client_body_buffer_size 128k;
proxy_connect_timeout ;
proxy_read_timeout ;
proxy_send_timeout ;
proxy_buffer_size 64k;
proxy_buffers 32k;
proxy_busy_buffers_size 128k;
proxy_http_version 1.1;
三.反向代理功能实现
#danny-test1
upstream danny-test1 {
ip_hash;
server 12.1.1.1:;
server 12.1.1.2:;
check interval= rise= fall= timeout= default_down=true type=http; //开启nginx状态检查
} #danny-test2
upstream danny-test2 {
ip_hash;
server 12.1.1.1:;
server 12.1.1.2:;
check interval= rise= fall= timeout= default_down=true type=tcp;
} #danny-web
upstream danny-web {
ip_hash;
server 12.1.1.1:;
server 12.1.1.1:;
check interval= rise= fall= timeout= default_down=true type=http;
} #danny-fs
upstream danny-fs {
ip_hash;
server 12.1.1.1:;
server 12.1.1.2:;
check interval= rise= fall= timeout= default_down=true type=tcp;
} #danny-order-web
upstream danny-order-web {
ip_hash;
server 12.1.1.1:;
server 12.1.1.1:;
check interval= rise= fall= timeout= default_down=true type=http;
} ####################################### server {
listen default;
listen ssl;
server_name blog.dannylinux.top; #ssl on;
ssl_certificate /usr/local/nginx/conf/ssl/server.pem;
ssl_certificate_key /usr/local/nginx/conf/ssl/server.key;
ssl_client_certificate /usr/local/nginx/conf/ssl/client.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1. TLSv1.;
ssl_ciphers HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM;
ssl_prefer_server_ciphers on;
#ssl_verify_client on; #####################################屏蔽爬虫
if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") {
return ;
} location ^~ /WEB-INF {
deny all;
} ##upstream status
location /upstream_status {
allow 12.1.1.3;
allow 13.1.0.0/;
allow 14.1.1.2;
allow 15.1.1.1;
# deny all;
check_status;
access_log off;
} ##nginx status
location /nginx_status {
allow 12.1.1.3;
allow 13.1.0.0/;
allow 14.1.1.2;
# deny all;
stub_status on;
access_log off;
} #danny-new-static
location ~ ^/(teststatic)/ {
root /opt/source/danny-static/;
} ##########3.0 proxy########## location / {
proxy_pass http://danny-web;
include /usr/local/nginx/conf/proxy.conf;
} #版本匹配
location ~ ^/(v(\d+)/danny-test1)/ {
proxy_pass http://danny-test1;
include /usr/local/nginx/conf/proxy.conf; #普通匹配
location ~ ^/(danny-test2) {
proxy_pass http://danny-test2;
include /usr/local/nginx/conf/proxy.conf;
} #条件匹配
#danny-fs
location ~ ^/(resource|upload)/ {
root /opt/proxy_temp; if (!-e $request_filename){
proxy_pass http://danny-fs;
}
proxy_cache imgcache;
proxy_cache_valid 30d;
proxy_cache_valid any 1d;
proxy_cache_key $host$uri$is_args$args; include /usr/local/nginx/conf/proxy.conf;
} #多条件匹配
#danny-order-web
location ~ ^/(v(\d+)/hehe|v(\d+)/haha|v(\d+)/yoyo|v(\d+)/wuwu|v(\d+)/xixi)/ {
proxy_pass http://danny-order-web;
include /usr/local/nginx/conf/proxy.conf;
}
以上都可单独为写为conf文件
企业nginx应用实例(功能拆分记录)的更多相关文章
- nginx下目录浏览及其验证功能配置记录
工作中常常有写不能有网页下载东西的需求,在Apache下搭建完成后直接导入文件即可达到下载/显示文件的效果;而Nginx的目录列表功能默认是关闭的,如果需要打开Nginx的目录列表功能,需要手动配置, ...
- PHP微信商户支付 - 企业付款到零钱功能(即提现)技术资料汇总
PHP实现微信开发中提现功能(企业付款到用户零钱) 一.实现该功能目的 这几天在小程序里要实现用户从系统中提现到零钱的功能,查了一下文档可以使用 企业付款到用户零钱 来实现: 官方文档:https:/ ...
- Nginx的常用功能
1.规范nginx的配置文件 在企业中我们的虚拟主机可能会很多,配置文件的内容也会有很多,这时候我们就可以规范一下我们的配置文件,把每个虚拟主机按照网站的域名或者是功能取名,放到统一的文件夹中,当然我 ...
- nginx缓存配置的操作记录梳理
web缓存位于内容源Web服务器和客户端之间,当用户访问一个URL时,Web缓存服务器会去后端Web源服务器取回要输出的内容,然后,当下一个请求到来时,如果访问的是相同的URL,Web缓存服务器直接输 ...
- centos6.5环境自动化运维之puppet实现nginx反向代理功能及puppet安装配置详解
puppet是一种Linux.Unix.windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统服务等.puppet把这些系统实体称之为资 ...
- Nginx 状态信息功能配置
Nginx 状态信息功能介绍 Nginx 有一个 ngx_http_stub_status_module 模块,主要功能是记录 Nginx 的基本访问状态信息,让使用者了解 Nginx 的工作状态 要 ...
- Nginx代理缓存功能
Nginx代理缓存功能 Nginx缓存主要是用于减轻后端服务器的负载,提高网站并发量,提升用户体验度. 注意:Nginx反向代理的缓存功能是由ngx_http_proxy_module提供, ...
- PHP微信商户支付企业付款到零钱功能
一 开通条件,就是首先要在微信平台设置好. 以下微信文档里有的,我这里大概掠几项比较重要的. 付款资金 企业付款到零钱资金使用商户号余额资金. 根据商户号的账户开通情况,实际出款账户有做区别: ◆ 默 ...
- Nginx Rewrite相关功能
目录 Nginx Rewrite相关功能 ngx_http_rewrite_module模块指令: if指令: set指令: break指令: return指令: rewrite_log指令: rew ...
随机推荐
- js cookie存取
if(getCookie('guide') == 'true'){ window.location.href='' } else { setCookie('guide','true'); } func ...
- 使用String. localeCompare比较字符串
javascript提供stringA.localeCompare(stringB)方法,来判断一个字符串stringB是否排在stringA的前面. 返回值: 如果引用字符存在于比较字符之前则 ...
- IBM Watson启示录:AI不应该仅仅是炫技
IBM Watson启示录:AI不应该仅仅是炫技 https://mp.weixin.qq.com/s/oNp8QS7vQupbi8fr5RyLxA 导 ...
- SAP MM MIGO & Return Delivery 组合实现部分数量的Reversal
SAP MM MIGO & Return Delivery 组合实现部分数量的Reversal 在笔者看来,MIGO这个事务代码里的Return Delivery主要用于采购退货场景. 先找到 ...
- getDimension与getDimensionPixelOffset与getDimensionPixelSize的区别
getDimension() 返回float型px值 精确 getDimensionPixelOffset() 返回int型px值 ...
- Kafka相关内容总结(存储和性能)
Kafka消息的存储 Kafka的设计基于一种非常简单的指导思想:不是要在内存中保存尽可能多的数据,在需要时将这些数据刷新(flush)到文件系统,而是要做完全相反的事情.所有数据都要立即写入文件系统 ...
- c/c++ 继承与多态 容器与继承1
问题:类B公有继承类A,类A有虚函数fun,类B覆盖了虚函数fun,有一个std::vector<A>,添加A的对象a,和B的对象b,到这个容器里,然后从vector里取出来,使用对象a. ...
- LVS负载均衡基础介绍及NET、DR模式配置
LVS:术语: CIP:Client IP:客户端IP: VIP:Virtual Server IP:虚拟主机对外IP: RIP:Real Server IP:真实主机IP: DIP:Director ...
- LeetCode算法题-Maximum Depth of N-ary Tree(Java实现)
这是悦乐书的第261次更新,第274篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第128题(顺位题号是559).给定n-ary树,找到它的最大深度.最大深度是从根节点到 ...
- C#基础知识之字符串比较方法:“==”操作符;RefernceEquals;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。
一.“==”操作符:String.Equals:ReferenceEquals 方法 1.在编程中实际上我们只需要这两种比较,c#中类型也就这两种 (1)值类型的比较:一般我们就是判断两个值类型实例各 ...