[英]Node.js and Apache for single domain same server
I built a RESTful website, and it is written in Angular2(front end) and Php(backend). 我建立了一个RESTful网站,它是用Angular2(前端)和Php(后端)编写的。 Since I am using Angular Universal, I need Node.js to pre-process the Angular scripts.
由于我正在使用Angular Universal,因此我需要Node.js来预处理Angular脚本。 How can I configure my server to host both Node.js and Apache?
如何配置服务器以同时托管Node.js和Apache? I searched online, but can't find any resources related to "sharing Node.js and Apache on SINGLE domain"...
我在线搜索,但找不到与“在单个域上共享Node.js和Apache”相关的任何资源...
How to configure my Apache to route "everthing" to the /dist/ folder (and served by Node.js) except for the URI that are prefix with /api/ and /uploads/ (route to the /php/ folder). 如何配置我的Apache以将“所有内容”路由到/ dist /文件夹(并由Node.js提供),但前缀为/ api /和/ uploads /的URI(路由到/ php /文件夹)除外。
[Back-end] Api Php script: [后端] Api Php脚本:
If www.example.com/api/?...?
如果是
www.example.com/api/?...?
, then use this script /var/www/example.com/public_html/php/api.php
to process it. ,然后使用此脚本
/var/www/example.com/public_html/php/api.php
进行处理。
Uploaded images: 上传的图片:
If asking for uploaded img files ( www.example.com/uploads/[img*.png]
), then try to look inside this /var/www/example.com/public_html/php/uploads/[img*.png]
folder. 如果要求上传的img文件(
www.example.com/uploads/[img*.png]
),请尝试查看此/var/www/example.com/public_html/php/uploads/[img*.png]
夹。
[Front-end] Html, Js, etc...: [前端] HTML,JS等...:
Everyting www.example.com
(except the /api/ and /uploads/), then ask Node.js to run it from this /var/www/example.com/public_html/dist/
folder. 每次使用
www.example.com
(/ api /和/ uploads /除外),然后要求Node.js从此/var/www/example.com/public_html/dist/
文件夹中运行它。
I guess it is related to proxy and proxy_http , but I don't know how to configure it since I can't find any resources related to sharing both systems for single domain
... 我猜它与proxy和proxy_http有关 ,但是我不知道如何配置它,因为我找不到与为
single domain
共享两个系统有关的任何资源...
i think you should Run Node.js on a different port (eg 8080) and use Reverse proxy in Apache config (virtual hosts) like this: 我认为您应该在其他端口(例如8080)上运行Node.js,并在Apache配置(虚拟主机)中使用反向代理,如下所示:
ProxyPass /api http://www.example.com/php/
ProxyPassReverse /api http://www.example.com/php/
ProxyPass /uploads http://www.example.com/php/uploads/
ProxyPassReverse /uploads http://www.example.com/php/uploads/
ProxyPass / http://www.example.com:8080/dist/
ProxyPassReverse / http://www.example.com:8080/dist/
and then use htaccess rewrite rules for your uploads and api 然后将htaccess重写规则用于您的上传和api
you can read more about mod_proxy 您可以阅读有关mod_proxy的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.