【问题标题】:Serving a NodeJS app via apache通过 apache 提供 NodeJS 应用程序
【发布时间】:2018-04-24 13:10:18
【问题描述】:

我正在我的 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>

【问题讨论】:

    标签: node.js apache server


    【解决方案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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-18
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-15
      • 1970-01-01
      • 2019-04-07
      相关资源
      最近更新 更多