我如何通过https服务reactjs应用程序? [英] How can I serve a reactjs app through https?

查看:80
本文介绍了我如何通过https服务reactjs应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在这里的第一篇文章.

好吧,在这里发表文章之前,我做了很多研究,但我真的不明白如何通过https协议为使用create-react-app创建(并用它编译/构建)的reactjs应用程序提供服务.

我已经获得了自签名证书,但是我使用的"serve" npm程序包(这是内置的create-react-app应用程序应使用的程序包)显然无法通过https提供.

我也尝试过更改服务器软件包,我尝试了 http-服务器除了我在应用程序中使用React Router且该服务器无法处理之外,对我来说是完美的选择.

我听说过要使用apache/nginx作为反向代理,有人可以向我解释它的工作原理吗?

祝你有美好的一天,加布(Gab)

解决方案

您必须先构建React应用npm run build,然后获取dist文件夹,然后使用您喜欢的Web服务器(例如Apache或Nginx)为其提供服务.

此中等帖子应该是一个很好的起点:

I also tried changing the server package, I tried http-server which seemed perfect for me except I use React Router in my app and this server can't deal with that.

I heard about using apache/nginx as a reverse proxy, could someone explain me how this works?

Have a nice day, Gab

解决方案

You have to build your React app npm run build, then, take the dist folder, and serve it using your favorite webserver, like Apache or Nginx.

This medium post should be a good starting point : https://medium.com/@jgefroh/a-guide-to-using-nginx-for-static-websites-d96a9d034940

Never ever serve a production app with Webpack Dev Server, it's a dev tool and it's not made for production.

这篇关于我如何通过https服务reactjs应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆