本文转自:https://blog.csdn.net/wly_er/article/details/82348593

目录

1.下载nginx。

2.测试nginx

3.配置react项目

4.nginx常用命令

1.下载nginx。

2.测试nginx
解压后,可以在cmd命令行输入:start nginx,开启服务,并在浏览器输入localhost,如果成功打开,则说明该nginx可以使用了。

出现该效果说明运行成功

3.配置react项目
我的项目打包后目录结构:

现在我们开始配置react项目

打开nginx.conf文件

在http里面添加一个server对象

server {
listen 8088;
server_name localhost;

root E:/items/react/rec-webp4/dist;
index index.html;

location / {
try_files $uri $uri/ @router;
index index.html;
}

location @router {
rewrite ^.*$ /index.html last;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
listen  :设置的端口号

server_name  :访问的名字

root   :你项目所放的地址

index index.html  :你的入口html文件

因为是单页应用,所以,是根据路由跳转,所以,为了避免出现404,我们需要重写至index.html

#根据路由设置,避免出现404
location / {

try_files $uri $uri/ @router;
index index.html;
}

location @router {
rewrite ^.*$ /index.html last;
}
设置代理:

nginx可以设置反向代理,解决跨域问题,我们可以这样设置:

# 匹配 api 路由的反向代理到API服务
location /api/ {
proxy_pass http://192.168.xxx.xxx:xxxx/;
}
这样,就会由:

http://localhost:10003/api/user/getuser...

转发至:

http://192.168.xxx.xxx:xxxx/user/getuser...

好了,现在,你就可以重启服务查看效果,(因为之前使用了start nginx ,所以这里可以直接reload重启)

nginx -s reload

4.nginx常用命令
nginx开启命令:start nginx

nginx停止命令:nginx -s quit

nginx重启命令:nginx -s reload

完~
---------------------
作者:wly_er
来源:CSDN
原文:https://blog.csdn.net/wly_er/article/details/82348593
版权声明:本文为博主原创文章,转载请附上博文链接!

[转]react 部署在ngnix上(windows环境)的更多相关文章

  1. 离线安装python第三方库的实用方法:解决公司内网,服务器/电脑不能上网却需要安装python三方库问题(上:Windows环境中)

    问题描述: 公司的windows电脑是内网,今天需要安装一个Twisted库,用过的应该都晓得,很常见的异步库,但是仅仅依靠Pypi上下载下来的离线.whl安装包是不行的,linux服务器都是远程连接 ...

  2. 基于Apache的阿里云部署Node.js服务器(Windows环境)

    1 前言 由于nodejs项目对方开放了多个端口,而且阿里云上的Apache服务器(windows)已经挂载了网站,此时需要把此项目也挂上去,网上查询资料,方法略少,基本是基于nginx版本的. 2  ...

  3. 六. jenkins部署springboot项目(3)--windows环境--远程windows server服务器

    前提:jenkins服务器和windows server服务器不在一台机器上 对于jenkins服务器上编译好的jar或war包如何推送到windows server服务器上. 参照网上的,在wind ...

  4. 五. jenkins部署springboot项目(2)--windows环境--服务

    前提:jenkins和springboot运行在同一台机器 springboot 通过winsw部署为服务 winsw 下载地址:https://github.com/kohsuke/winsw/re ...

  5. VUE项目部署到线上生产环境,Loading chunk xxx failed

    项目部署到生产环境,路由点击无效,报错 Loading chunk chunk-xxxxx failed.(missing xxxx) 加载失败,错误的路径. 话不多说,直接贴代码: vue.conf ...

  6. 本地Jmeter脚本部署在Jenkins上 - Windows

    一.下载并安装Jenkins(不进行特别的说明) 二.准备好jmeter脚本 三.插件准备:Publish HTML reports 四.开始 1.登录Jenkins后,点击新建任务 2.输入项目名, ...

  7. Windows环境安装Linux系统及JDK部署

    前言 由于我的笔记本有点问题,所以这周系统包括所有硬盘全部重装了,原来的Linux虚拟机都没了,因此才有了这篇文章和各位朋友们分享. 由于Linux环境的优越性(开源.低成本.安全性好.网络功能强大) ...

  8. 通达OA2008从windows环境移植到linux部署手册

    通达OA2008从windows环境移植到linux中(centos5.5及以上版本) OA系统拓扑图: 环境搭建(安装lamp环境) 1.安装xampp集成lamp包xampp-linux-1.6. ...

  9. windows环境下安装部署并启用zkui的web图形界面

    在此之前的工作:不是本机部署的三个服务器最为伪集群的zookeeper环境,并将三个为服务启动起来. 然后才有了下面的工作. 1. 首先,zkui项目地址:https://github.com/Dee ...

随机推荐

  1. Prometheus 自定义exporter 监控key

    当Prometheus的node_exporter中没有我们需要的一些监控项时,就可以如zabbix一样定制一些key,让其支持我们所需要的监控项. 例如,我要根据 逻辑cpu核数 来确定load的告 ...

  2. C# yield return 和 yield break

    yield关键字用于遍历循环中,yield return用于返回IEnumerable<T>,yield break用于终止循环遍历. 以下对比了使用yield return与不使用yie ...

  3. [Codeforces Round #516][Codeforces 1063B/1064D. Labyrinth]

    题目链接:1063B - Labyrinth/1064D - Labyrinth 题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x ...

  4. sublime No packages available for installation

    package control user-setting 中添加: "channels": [ "C:\\channel_v3.json" ], channel ...

  5. oracle启动服务和监听

    1.故障问题:tomcat显示启动oracle数据库失败,数据库服务启动正常 操作1:重启tomcat查看错误信息 2:重启数据库服务 命令: (1) 启动Oracle服务 C:\Users\Admi ...

  6. Springboot 集成jpa使用

    实体类 dao层 上面的查询 ,方法名友好命名的话,可以不写注解查询  findByXXXX MetadataSchemePO findBySchemeName(String schemeName); ...

  7. java小练习

    打印99乘法表 因为有9行9列,所有要用两个for循环 int m; for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) ...

  8. postman run之前需要手动调整顺序

    最近刚入坑postman,记录下遇到的坑: 1.先用postman interceptor录制好脚本,在postman中,将History的脚本导入Collections,由于项目接口之间需要toke ...

  9. QEMU KVM Libvirt手册(11): Managing Storage

    When managing a VM Guest on the VM Host Server itself, it is possible to access the complete file sy ...

  10. [Swift]LeetCode173. 二叉搜索树迭代器 | Binary Search Tree Iterator

    Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the ro ...