需求:

 此时前台开发完成打包生成静态资源文件,要做到以下方面:
  使用nginx部署静态资源,同时nginx要实现端口转发,隐藏真实后台地址,同时后台需要做一个负载均衡。
  localhost:7001是前台地址,访问后台localhost:7001/backend  转发到 192.168.249.144:7001/backend  
 
nginx.conf配置如下
#user  nobody;
worker_processes ;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
charset utf-;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout ;
keepalive_timeout ;
client_max_body_size 64m;
client_header_buffer_size 16k;
client_header_timeout ;
client_body_timeout ;
open_file_cache max= inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses ;
underscores_in_headers on;
#gzip on;
gzip on; gzip_min_length 1k;
gzip_buffers 16k;
gzip_http_version 1.0;
gzip_comp_level ;
gzip_proxied any;
gzip_types text/plain application/x-javascript application/javascript text/css application/json text/javascript image/jpeg image/jpg image/gif image/png application/x-bmp application/x-shockwave-flash application/xml+rss;
gzip_vary on;
gzip_disable "MSIE [1-6]\."; fastcgi_connect_timeout ;
fastcgi_send_timeout ;
fastcgi_read_timeout ;
fastcgi_buffer_size 64k;
fastcgi_buffers 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
upstream cfsCluster{
   ip_hash;
server 192.168.249.144:;
}
server {
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
add_header backendIp $upstream_addr;
root C:\Users\lidedong\Desktop\dist;
index index.html;
}
location /backend {
proxy_pass http://cfsCluster;
add_header backendIp $upstream_addr;
add_header backendCode $upstream_status;
proxy_set_header X-Real_Ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
}
} }

常用的代理配置粘上:

# proxy.conf
# proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Connection "";
proxy_set_header Cookie $http_cookie;
#proxy_set_header x_enb_token $x_enb_token;
#proxy_set_header x_enb_userid $x_enb_userid;
#proxy_set_header x_enb_ctime $x_enb_ctime;
#proxy_set_header x_enb_clientid $x_enb_clientid;
client_max_body_size 64m;
client_body_buffer_size 128k;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
proxy_buffers 8k;
proxy_buffer_size 16k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_headers_hash_max_size ;
proxy_ignore_client_abort on;

nginx做为web容器部署静态资源以及做负载均衡反向代理实现的更多相关文章

  1. Nginx服务器部署 负载均衡 反向代理

    Nginx服务器部署负载均衡反向代理 LVS Nginx HAProxy的优缺点 三种负载均衡器的优缺点说明如下: LVS的优点: 1.抗负载能力强.工作在第4层仅作分发之用,没有流量的产生,这个特点 ...

  2. Nginx HTTP负载均衡/反向代理的相关参数测试

    原文地址:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/03/15/1984976.html 测试目的 (1)弄清楚HTTP Upstr ...

  3. 激活web容器对静态资源的默认servlet处理

    在某些servlet的url匹配模式使用/时会拦截一些静态的资源的请求导致无法正确访问,可以采取web容器默认的servlet来处理,当然那些mvc一般也都提供了处理的方法,用何种方式可以自行决定,这 ...

  4. 架构之Nginx(负载均衡/反向代理)

    Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器 ,也是一个 IMAP/POP3/SMTP 代理 服务器 . Nginx 是由 Igor Sys ...

  5. nginx域名转发 负载均衡 反向代理

    公司有三台机器在机房,因为IP不够用,肯定要分出来,所以要建立单IP 多域名的反向代理, 就是当请求www.abc.com 跳转到本机, 请求www.bbc.com 跳转到192.168.0.35 机 ...

  6. nginx 负载均衡 反向代理

    nginx 通过方向代理实现负载均衡,负载均衡是大流量网站要做的措施,单从字面上的意思来理解为N台服务器平均分担负载,不会因为某一台服务器负载高宕机而影响用户访问网站,负载均衡至少需要三台服务器, 既 ...

  7. Nginx负载均衡反向代理 后端Nginx获取客户端真实IP

    Nginx 反向代理后,后端Nginx服务器无法正常获取客户端的真实IP nginx通过http_realip_module模块来实现的这需要重新编译,如果提前编译好了就无需重新编译了1,重新编译ng ...

  8. nginx负载均衡(反向代理)

    6,安装nginx 6.1 依赖库安装  要安装在root根目录里,不要装在虚拟环境里面 yum install gcc-c++ pcre pcre-devel zlib zlib-devel ope ...

  9. keepalived + nginx(负载均衡反向代理HTTP,https) + tomcat(HTTP,https)

    基本架构: nginx(192.168.116.198) client        --->keepalived(116.200)      ------> tomcat (192.16 ...

随机推荐

  1. jQuery源代码学习之十——动画Animate

    一.Animate模块的代码结构 // 定义了一些变量 tweeners = {}; function createFxNow() {} function createTween() {} funct ...

  2. Apache Flink - 基本API概念

    Flink程序是实现分布式集合转换的常规程序.集合最初是从源创建的.通过接收器(slink)返回结果,接收器可以将数据写到某个文件或stdout.Flink可以在各种环境(context)中运行,本地 ...

  3. 课下选做作业MyOD

    2019-2020-1 20175227 <信息安全系统设计基础> 课下选做作业MyOD 要求 复习c文件处理内容 编写myod.c 用myod XXX实现Linux下od -tx -tc ...

  4. ? 这是个很好的问题。Go 当前的 GC 显然做了一些额外的工作,但它也跟其他的工作并行执行,所以在具有备用 CPU 的系统上,Go 正在作出合理的选择。请看 https://golang.org/issue/17969 结束语(Closing notes) 通过研究 Go 垃圾收集器,我能够理解 Go GC 当前结构的背景以及它如何克服它的弱点。Go发展得非常快。如果你对 Go感兴趣,最好继

    ? 这是个很好的问题.Go 当前的 GC 显然做了一些额外的工作,但它也跟其他的工作并行执行,所以在具有备用 CPU 的系统上,Go 正在作出合理的选择.请看 https://golang.org/i ...

  5. Go 代码审查建议

    https://github.com/golang/go/wiki/CodeReviewComments https://studygolang.com/articles/6054

  6. pycharm2019没有database问题(关于社区版)

    原文链接:https://blog.csdn.net/BlacK_CaT_/article/details/53884806网上教程都是直接打开右上角的database,但是我死活也没找到,后来发现应 ...

  7. js for (i=0;i<a.length;a[i++]=0) 中等于0怎么理解?

    js的问题for (i=0;i<a.length;a[i++]=0) 中等于0怎么理解? 很奇怪的一个for循环 竟然是将原来数组的数据全改为0

  8. set serveroutput on

    使用set serveroutput on 命令设置环境变量serveroutput为打开状态,从而使得pl/sql程序能够在SQL*plus中输出结果 使用函数dbms_output.put_lin ...

  9. springboot整合redis(集群)

    一.加入maven依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId> ...

  10. Qt编写数据可视化大屏界面电子看板5-恢复布局

    一.前言 恢复布局这个功能在整个数据可视化大屏界面电子看板系统中非常有用,很多时候不小心把现有布局拖动乱了,(当然如果不想布局被拖动改动,可以修改配置文件中的MoveEnable参数来控制,默认为真表 ...