简体   繁体   English

Apache2 和 node.js 应用程序在网络服务器上同时运行

[英]Apache2 and node.js app running simultaneously on webserver

I would like to run apache2 and a node.js app on my webserver simultaneously.我想同时在我的网络服务器上运行 apache2 和 node.js 应用程序。 I'd like my website on www.example.com/myApp to run my app (proxied from port 8080), and everything else on www.example.com/* to be run by apache (normally on port 80).我希望 www.example.com/myApp 上的网站运行我的应用程序(从端口 8080 代理),而 www.example.com/* 上的所有其他内容都由 apache 运行(通常在端口 80 上)。 I've read a couple of questions about this on StackOverflow but I couldn't get it to work properly.我已经在 StackOverflow 上阅读了几个关于这个的问题,但我无法让它正常工作。

I am using我在用

yarn start --port 8080 --host 0.0.0.0 --disable-host-check

to start my app.启动我的应用程序。

In order to do this I was changing values in my apache.conf file on my Ubuntu 18.04 VM.为了做到这一点,我在 Ubuntu 18.04 VM 上更改了 apache.conf 文件中的值。 I am running my app with yarn.我正在用纱线运行我的应用程序。

I enabled我启用

sudo a2enmod proxy && sudo a2enmod proxy_http

and I have these lines in my config file:我的配置文件中有这些行:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ServerName example.com
ProxyPreserveHost On
ProxyRequests Off

If I add如果我添加

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

to my apache.conf file, the app runs successfully on www.example.com .到我的 apache.conf 文件,该应用程序在www.example.com 上成功运行。 However, I can only access directories from the folder in which the app is installed/running.但是,我只能从安装/运行应用程序的文件夹访问目录。 I cannot access apache's directories.我无法访问 apache 的目录。

If instead I add如果相反我添加

ProxyPass /myApp/ http://localhost:8080/
ProxyPassReverse /myApp/ http://localhost:8080/

then the app runs on www.example.com/myApp , which IS what I wanted, but it does not run correctly anymore, and I don't know why.然后应用程序在www.example.com/myApp 上运行,这是我想要的,但它不再正确运行,我不知道为什么。 Every other url on the website points to my apache dir (/var/www/html) which is also what I wanted.网站上的每个其他 url 都指向我的 apache 目录 (/var/www/html),这也是我想要的。

The app always works properly on localhost:8080.该应用程序始终在 localhost:8080 上正常运行。

I have no experience with these things and it feels like I'm really close with the second solution, but I must be missing something since the app stops working correctly.我对这些事情没有经验,感觉我真的很接近第二个解决方案,但是由于应用程序停止正常工作,所以我必须遗漏一些东西。

I managed to solve the problem with this configuration:我设法解决了这个配置的问题:

ProxyPass /index.html http://0.0.0.0:8080/
ProxyPassReverse /index.html http://0.0.0.0:8080/

ProxyPass /config http://0.0.0.0:8080/config/
ProxyPassReverse /config http://0.0.0.0:8080/config/
ProxyPass /css http://0.0.0.0:8080/config/
ProxyPassReverse /css http://0.0.0.0:8080/config/
...

so, by creating a proxy pass to an index.html file and adding proxies for all subfolders in the app's folder.因此,通过为 index.html 文件创建代理传递并为应用程序文件夹中的所有子文件夹添加代理。 I helped myself with questions like this and this .我顺手拿有这样的问题这个这个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM