我在apache2 web服务器上运行nodejs应用程序。在尝试访问域页面example.com
时,它会显示默认的apache页面而不是应用程序页面。但是在转到example.com:8090
时,它会显示节点应用程序
这是配置
<VirtualHost *80>
ServerName example.com
ServerAlias www.example.com
ProxyRequests off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://serverip:8090
ProxyPassReverse http://serverip:8090
</Location>
</VirtualHost>
答案 0 :(得分:1)
这将有效,只要知道它在意识形态上不是最优雅的解决方案。
# Main site proxy
<VirtualHost *:80>
ServerAlias www.example.com
ServerName example.com
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://nodejsIP:8090/
ProxyPassReverse / http://nodejsIP:8090/
</VirtualHost>
# Subdomain proxies
<VirtualHost *:80>
ServerAlias www.api.example.com
ServerName api.example.com
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://nodejsIP:8090/api/
ProxyPassReverse / http://nodejsIP:8090/api/
</VirtualHost>
<VirtualHost *:80>
ServerAlias www.apps.example.com
ServerName apps.example.com
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://nodejsIP:8090/apps/
ProxyPassReverse / http://nodejsIP:8090/apps/
</VirtualHost>
注意:如果您的apache服务器和节点服务器都在同一个盒子上运行,因此具有相同的IP,请使用http://localhost作为 nodejsIP