Ngnix反向代理react-router配置问题解决方法
项目以react router实现,用ngnix做反向代理的时候出现404找不到页面,有两种解决方法。
第一种 将<Route path="*" component={NotFound} />对应的component改为<IndexRoute>对应的component,如下:
const Routes = ({ history }) =>
<Router history={history}>
<Route path="/" component={Index}>
<IndexRoute component={DefaultPage}/>
<Route path="/lc" component={DefaultPage} />
<Route path="/Icon" component={Icon} />
<Route path="/ECharts" component={ECharts} />
<Route path="/page1" component={Page1} />
<Route path="/page3" component={Index} />
<Route path="/ruleJson" component={ruleJson} />
<Route path="/rules" component={rules} />
<Route path="/dataSource" component={DataSource}/>
<Route path="/viewTable" component={ViewTable}/>
<Route path="/sourceMatch" component={SourceMatch}/>
<Route path="/addMatchRules" component={AddMatchRules}/>
<Route path="seeMatchRules" component={SeeMatchRules}/>
<Route path="projectSourceUse" component={ProjectSourceUse}/>
<Route path="kafkaConfig" component={KafkaConfig}/>
<Route path="dataLocate" component={DataLocate}/>
<Route path="configurationEnvironment" component={ConfigurationEnvironment}/>
<Route path="mainframeInfo" component={MainframeInfo}/>
<Route path="resInfo" component={ResInfo}/>
<Route path="askForRes" component={AskForRes}/>
<Route path="releaseTask" component={ReleaseTask}/>
<Route path="taskList" component={TaskList}/>
<Route path="taskList" component={TaskList}/>
<Route path="taskList" component={TaskList}/>
<Route path="*" component={DefaultPage} />
</Route>
</Router>
此时 Ngnix服务端配置如下
server {
listen 80;
server_name localhost;
proxy_redirect http://localhost:3083/ /;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://10.248.26.202;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /pt/ {
proxy_pass http://10.248.26.202:3083;
rewrite "^/pt(.*)$" $1 break;
}
location /help/ {
proxy_pass http://10.248.26.202/help;
}
location ~^/lc/ {
proxy_pass http://localhost:8080;
rewrite "^/lc(.*)$" $1 break;
}
}
此时代理成功 但是字体加载不到 根据404请求的地址所以添加一个字体的规则
location ^~/fonts/{
rewrite "^(.*)/fonts(.*)$" $1/lc/fonts$2;
}
第二种方法
在路由中添加一条与uri对应的路径指向首页 如下
const Routes = ({ history }) =>
<Router history={history}>
<Route path="/" component={Index}>
<IndexRoute component={DefaultPage}/>
<Route path="/lc" component={DefaultPage} />
<Route path="/Icon" component={Icon} />
<Route path="/ECharts" component={ECharts} />
<Route path="/page1" component={Page1} />
<Route path="/page3" component={Index} />
<Route path="/ruleJson" component={ruleJson} />
<Route path="/rules" component={rules} />
<Route path="/dataSource" component={DataSource}/>
<Route path="/viewTable" component={ViewTable}/>
<Route path="/sourceMatch" component={SourceMatch}/>
<Route path="/addMatchRules" component={AddMatchRules}/>
<Route path="seeMatchRules" component={SeeMatchRules}/>
<Route path="projectSourceUse" component={ProjectSourceUse}/>
<Route path="kafkaConfig" component={KafkaConfig}/>
<Route path="dataLocate" component={DataLocate}/>
<Route path="configurationEnvironment" component={ConfigurationEnvironment}/>
<Route path="mainframeInfo" component={MainframeInfo}/>
<Route path="resInfo" component={ResInfo}/>
<Route path="askForRes" component={AskForRes}/>
<Route path="releaseTask" component={ReleaseTask}/>
<Route path="taskList" component={TaskList}/>
<Route path="taskList" component={TaskList}/>
<Route path="taskList" component={TaskList}/>
<Route path="*" component={DefaultPage} />
</Route>
</Router>
此时ngnix服务器端的配置如下
server {
listen 80;
server_name localhost;
proxy_redirect http://localhost:3083/ /;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://10.248.26.202;
}
location /pt/ {
proxy_pass http://10.248.26.202:3083;
rewrite "^/pt(.*)$" $1 break;
}
location /help/ {
proxy_pass http://10.248.26.202/help;
}
location ~^/lc/ {
proxy_pass http://localhost:8080;
rewrite "^/lc(.*)$" $1 break;
}
Ngnix反向代理react-router配置问题解决方法的更多相关文章
- [跨域]跨域解决方法之Ngnix反向代理
跨域原理:http://www.cnblogs.com/Alear/p/8758331.html 介绍Ngnix之前,我么先来介绍下代理是什么~ 代理相当于中间人,中介的概念 代理分为正向代理和反向代 ...
- 正向代理 forward proxy、反向代理 reverse proxy、透明代理 transparent proxy nginx反向代理原理和配置讲解 防止外部客户机获取内部内容服务器的重定向 URL 缓存命中
[大型网站技术实践]初级篇:借助Nginx搭建反向代理服务器 - Edison Chou - 博客园http://www.cnblogs.com/edisonchou/p/4126742.html 图 ...
- Nginx反向代理负载均衡配置
1.反向代理概述 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求 ...
- Nginx反向代理讲解和配置
首先来介绍下Nginx的反向代理.代理服务器一般分为正向代理(通常直接称为代理服务器)和反向代理. 画个图我们就好理解了. 正向代理:可以想象成是路由器,我们要通过它来上网的那种.(可以说是客户端的代 ...
- ngnix 反向代理
1 课程目标 掌握nginx+tomcat反向代理的使用方法. 掌握nginx作为负载均衡器的使用方法. 掌握nginx实现web缓存方法. 2 nginx介绍 2.1 ...
- Nginx实战之反向代理WebSocket的配置实例
http://www.jb51.net/article/112183.htm 最近在工作中遇到一个需求,需要使用 nginx 反向代理websocket,经过查找一番资料,目前已经测试通过,所以这篇文 ...
- Nginx反向代理的基本配置
(1)proxy_pass 语法:proxy_pass URL; 配置块:location.if 此配置项将当前请求反向代理到URL参数指定的服务器上,URL可以是主机名或IP地址加端口的形式,例如: ...
- Linux 下 Nginx 反向代理 负载均衡配置
转载请注明出处:http://blog.csdn.net/smartbetter/article/details/52036350 上一篇分享了 Nginx + JDK + Tomcat + MySQ ...
- nginx反向代理做cache配置
前序:请耐性子看完,前面的这个配置可以达到按后缀名进行缓存,但无法被purge.后面的配置可以被purge.具体实施方案按个人情况而定. 需要第三方的ngx_cache_purge模块:wget ht ...
随机推荐
- 网站推广优化(SEO,网站关键字优化,怎么优化网站,如何优化网站关键字)
网站推广优化教程100条(完整版)下面介绍新手建站推广完美教程,各位根据自己的实际情况酌情选用: 1.准备个好域名.①.尽量在5位数内,当然也不一定,反正要让用户好记.(看个人):②.尽量用顶级的域名 ...
- SSIS自定义数据流组件开发(血路)
由于特殊的原因(怎么特殊不解释),需要开发自定义数据流组件处理. 查了很多资料,用了不同的版本,发现各种各样的问题没有找到最终的解决方案. 遇到的问题如下: 用VS2015编译出来的插件,在SSDTB ...
- 实现windows批处理下的计时功能
有时在执行完一段windows的批处理后,想知道这个过程花费了多少时间,如果是windows下的c代码可以在过程前后分别调用GetTickCount(),然后相减即可得到花费的时间. 但是如果在批处理 ...
- 《舌尖上的中国》第二季今日首播了,天猫食品也跟着首发,借力使力[bubuko.com]
天猫旗下的天猫食品与央视CCTV-1栏目<舌尖上的中国>第二季(以下简称“舌尖2”)达成合作,天猫食品成为舌尖2独家合作平台,同步首发每期 节目中的食材和美食菜谱,舌尖2摄制组还将为同步上 ...
- mybatis实战教程(mybatis in action)之十:mybatis SqlSessionSupport 的使用,构件DAO 层的应用
前面的系列mybatis 文章,已经基本讲到了mybatis的操作,但都是基于mapper隐射操作的,在mybatis 3中这个mapper 接口貌似充当了以前在ibatis 2中的 DAO 层的作用 ...
- C#中Validating和Validated事件
http://blog.sina.com.cn/s/blog_6116673a0100fpeo.html 待解读
- asp.net中如何防止用户重复点击提交按钮
asp.net中如何防止用户重复点击提交按钮 asp.net 中防止因为网速慢等影响交互的问题导致用户可能点击多次提交按钮,从而导致数据库中出现多条重复的记录,经过亲自验证在网上找的方法,找到两个 ...
- CRM 2016 子表单中N:1关系 字段要求与新建时的关系
父表单在新建子表单项时弹出的窗口和 子表单的N:1关系是有关系的.说白了就是子表单窗体上的父表单字段是不是必填项. 关系如下: 1 非必填项 点击子表单的"+"号时,会出现look ...
- 【原创】Java批量反编译利器(jd-gui)介绍
Java反编译利器(jd-gui)介绍 当要做白盒测试或安全测试时,我们需要借助工具扫描被测代码,相信大家都遇到过没有源代码,而需要反编译的情形吧,也可能大家用过jad工具,我这里介绍下方便的工具jd ...
- eclipse 断点使用深入技能
原文:http://blog.jobbole.com/26435/ 摘要:调试不仅可以查找到应用程序缺陷所在,还可以解决缺陷.对于Java程序员来说,他们不仅要学会如何在Eclipse里面开发像样的程 ...