一.默认访问协议强制跳转(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应用实例(功能拆分记录)的更多相关文章

  1. nginx下目录浏览及其验证功能配置记录

    工作中常常有写不能有网页下载东西的需求,在Apache下搭建完成后直接导入文件即可达到下载/显示文件的效果;而Nginx的目录列表功能默认是关闭的,如果需要打开Nginx的目录列表功能,需要手动配置, ...

  2. PHP微信商户支付 - 企业付款到零钱功能(即提现)技术资料汇总

    PHP实现微信开发中提现功能(企业付款到用户零钱) 一.实现该功能目的 这几天在小程序里要实现用户从系统中提现到零钱的功能,查了一下文档可以使用 企业付款到用户零钱 来实现: 官方文档:https:/ ...

  3. Nginx的常用功能

    1.规范nginx的配置文件 在企业中我们的虚拟主机可能会很多,配置文件的内容也会有很多,这时候我们就可以规范一下我们的配置文件,把每个虚拟主机按照网站的域名或者是功能取名,放到统一的文件夹中,当然我 ...

  4. nginx缓存配置的操作记录梳理

    web缓存位于内容源Web服务器和客户端之间,当用户访问一个URL时,Web缓存服务器会去后端Web源服务器取回要输出的内容,然后,当下一个请求到来时,如果访问的是相同的URL,Web缓存服务器直接输 ...

  5. centos6.5环境自动化运维之puppet实现nginx反向代理功能及puppet安装配置详解

    puppet是一种Linux.Unix.windows平台的集中配置管理系统,使用自有的puppet描述语言,可管理配置文件.用户.cron任务.软件包.系统服务等.puppet把这些系统实体称之为资 ...

  6. Nginx 状态信息功能配置

    Nginx 状态信息功能介绍 Nginx 有一个 ngx_http_stub_status_module 模块,主要功能是记录 Nginx 的基本访问状态信息,让使用者了解 Nginx 的工作状态 要 ...

  7. Nginx代理缓存功能

    Nginx代理缓存功能      Nginx缓存主要是用于减轻后端服务器的负载,提高网站并发量,提升用户体验度. 注意:Nginx反向代理的缓存功能是由ngx_http_proxy_module提供, ...

  8. PHP微信商户支付企业付款到零钱功能

    一 开通条件,就是首先要在微信平台设置好. 以下微信文档里有的,我这里大概掠几项比较重要的. 付款资金 企业付款到零钱资金使用商户号余额资金. 根据商户号的账户开通情况,实际出款账户有做区别: ◆ 默 ...

  9. Nginx Rewrite相关功能

    目录 Nginx Rewrite相关功能 ngx_http_rewrite_module模块指令: if指令: set指令: break指令: return指令: rewrite_log指令: rew ...

随机推荐

  1. C# 消息队列-Microsoft Azure service bus 服务总线

    先决条件 Visual Studio 2015或更高版本.本教程中的示例使用Visual Studio 2015. Azure订阅. 注意 要完成本教程,您需要一个Azure帐户.您可以激活MSDN订 ...

  2. Java虚拟机学习笔记(一)

    Java虚拟机运行时数据区域 Java虚拟机将其所管理的内存划分为若干个不同的数据区域.这些区域都有着各自的用途,以及创建和销毁时间.其中有一些会随着虚拟机启动而启动,随着虚拟机退出而销毁:有些则是与 ...

  3. Fundebug前端JavaScript插件更新至1.6.0,新增test()方法用于测试

    摘要: 1.6.0新增fundebug.test()方法用于测试,请大家及时更新. 默认情况下,Fundebug 插件能够自动捕获未处理的错误(uncaught error).另外,开发者也可以通过使 ...

  4. Android远程桌面助手(Build 0662)

    ARDC Build 0662, Jul 19, 2017 OPT: 1440*2560及以下分辨率设备,帧速能稳定在20帧~25帧 FIX: 拖拽文件的路径中包含空格的处理 ADD: 支持Ctrl+ ...

  5. 测者的测试技术手册:AI的自动化单元测试

    测者的测试技术手册:AI的自动化单元测试 谈新技术:AI的自动化单元测试    

  6. MongoDB 如何实现备份压缩

    背景及原理 数据库的备份是灾难恢复的最后一道屏障,不管什么类型的数据库都需要设置数据库备份,MongoDB也不例外.MongoDB 3.0 后 ,数据库可以采用Wiredtiger存储引擎后(3.2 ...

  7. Linux 中NFS服务器的搭建

    serve端IP:192.168.2.128 客户端IP:192.168.2.131 server端配置: 1.安装nfs,rpcbind,可以参考Linux 中yum的配置来安装: yum inst ...

  8. 彻底删除mysql服务(清理注册表)

    由于安装某个项目的执行文件,提示要卸载MySQL以便它自身MySQL安装,然后我禁用了MYSQL服务,再把这个文件夹删除后,发现还是提示请卸载MYSQL服务. 解决步骤: 1.以管理员身份运行命令提示 ...

  9. C++17剖析:string_view的实现,以及性能

    主要内容 C++17标准发布,string_view是标准新增的内容.这篇文章主要分析string_view的适用范围.注意事项,并分析string_view带来的性能提升,最后从gcc 8.2的li ...

  10. 基于TCP 协议的RPC

    前言: 环境: windown 10 Eclipse JDK 1.8 RPC的概念: RPC 是远程过程调用,是分布式网站的基础. 实验 SayHelloService.java 接口类,用于规范 S ...