服务Reactjs+ Ubuntu服务器上的PHP

发布于 2025-01-23 06:06:30 字数 1063 浏览 6 评论 0原文

我正在研究我的第一个Web项目,因此拥有带有Apache2的Ubuntu机器。我是Web开发的新手,以前从未部署过网站。很抱歉,如果这个问题听起来很愚蠢,但是用同一台机器提供reactjs Front和PHP后端的网站的最佳方法是什么?我现在正在搜索网络几天,并尝试了许多可能的方法,但是它们都没有按预期工作。

我非常简化的文件夹结构当前是:

github-test
 ┣ build
 ┃ ┣ static
 ┃ ┃ ┣ css
 ┃ ┃ ┗ js
 ┃ ┣ asset-manifest.json
 ┃ ┗ index.html
 ┣ public
 ┃ ┗ index.html
 ┣ src
 ┃ ┣ App.js
 ┃ ┣ index.js
 ┣ server
 ┃ ┣ classes
 ┃ ┃ ┣ ActionsContr.class.php
 ┃ ┃ ┣ DBh.class.php
 ┃ ┣ includes
 ┃ ┃ ┗ getUsers.inc.php
 ┣ asset-manifest.json
 ┣ package-lock.json
 ┣ package.json
 ┗ README.md

在此结构中,我的apache2用package.json提供了整个目录

homepage: 'build'

。我目前使用此文件夹结构和服务器配置,允许Apache2使用我的PHP代码。不幸的是,这将我的IP更改为

xxx.xxx.xxx.xxx/build

,对我来说既不优雅又安全。

我的第一个文件夹结构是在项目文件夹中具有A /客户端和 /服务器目录,这导致IP地址更长。我尝试将服务器目录移至构建文件夹中,但是随着每个生产构建删除此文件夹,这不是最好的选择。

我还考虑使用两个虚拟霍斯特人,一个用于前端,但我只是无法运行它。

告诉我您是否需要更多信息。谢谢

编辑 我让它运行了,我的错误是,在UFW中启用后端的端口,并在后端VirtualHost中的路径中启用了错字。最后,我使用了两个单独的文件夹(一个用于后背,另一个用于前后),在端口80(前)和8080(Back)上创建了两个虚拟主机。

I am working on my first web-project and therefore have an Ubuntu machine with apache2. I am quite new to web development and have never deployed a website before. I am sorry if this question sounds stupid, but what is the best way to serve a website with ReactJS front and PHP back end from the same machine? I am searching the web for days now and tried lots of possible ways, but none of them seamed to have worked as expected.

My very simplified folder structure is currently:

github-test
 ┣ build
 ┃ ┣ static
 ┃ ┃ ┣ css
 ┃ ┃ ┗ js
 ┃ ┣ asset-manifest.json
 ┃ ┗ index.html
 ┣ public
 ┃ ┗ index.html
 ┣ src
 ┃ ┣ App.js
 ┃ ┣ index.js
 ┣ server
 ┃ ┣ classes
 ┃ ┃ ┣ ActionsContr.class.php
 ┃ ┃ ┣ DBh.class.php
 ┃ ┣ includes
 ┃ ┃ ┗ getUsers.inc.php
 ┣ asset-manifest.json
 ┣ package-lock.json
 ┣ package.json
 ┗ README.md

Within this structure my apache2 serves the whole directory with package.json leading to:

homepage: 'build'

for production. I currently use this folder structure and server configuration, to allow apache2 to serve my php code. Unfortunately this changes my IP to

xxx.xxx.xxx.xxx/build

which seams neither elegant nor safe to me.

My first folder structure was to have a /client and /server directory in my project folder, which lead to a still longer IP address. I tried moving the server directory into the build folder, but as this folder gets deleted with every production build, this can not be the best option.

I was also thinking of using two VirtualHosts, one for front, one for backend, but I just could not get it running.

Tell me if you need further information. Thanks

Edit
I got it running, my mistake was, to enable the port for the backend in ufw and a typo in the path in the back end VirtualHost. In the end I used two seperate folders (one for back and one for front), created two VirtualHosts on ports 80 (front) and 8080 (back).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文