2013-01-10 9 views
21

Problema: ho bisogno di ospitare un'applicazione nodo e un'applicazione php sullo stesso server su domini diversi.Apache + Node.js + mod_proxy. Come indirizzare un dominio a: 3000 e un altro a: 80

example.com dovrebbe utilizzare la porta 80 come di consueto, ma node-example.com dovrebbe itinerario alla porta 3000.

dirigendo tutto il traffico dalla porta 80-3000 funziona bene utilizzando mod_proxy, questa convenzione:

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName node-example.com 
    ServerAlias www.node-example.com 

    ProxyRequests off 

    <Proxy *> 
      Order deny,allow 
      Allow from all 
    </Proxy> 

    <Location /> 
      ProxyPass http://localhost:3000/ 
      ProxyPassReverse http://localhost:3000/ 
    </Location> 

</VirtualHost> 

Ciò tuttavia fa sia example.com che node-example.com per puntare a localhost: 3000 ed eseguire l'app Node.

C'è un modo per mantenere example.com per puntare alla porta 80?

Sarebbe anche bene per example.com/old-admin per puntare alla porta 80.

+0

hai avuto successo? – Fardin

risposta

27

Basta fare due <VirtualHost *:80> tag

<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName www.node-example.com 

    ProxyRequests off 

    <Proxy *> 
      Order deny,allow 
      Allow from all 
    </Proxy> 

    <Location /> 
      ProxyPass http://localhost:3000/ 
      ProxyPassReverse http://localhost:3000/ 
    </Location> 

</VirtualHost> 
<VirtualHost *:80> 
    ServerAdmin [email protected] 
    ServerName node-example.com  

    ProxyRequests off 

    <Proxy *> 
      Order deny,allow 
      Allow from all 
    </Proxy> 

    <Location /> 
      ProxyPass http://localhost:80/ 
      ProxyPassReverse http://localhost:80/ 
    </Location> 

</VirtualHost> 

Dovrebbe funzionare in questo modo;)

Oppure se l'app localhost:80 non è un nodo, puoi rimuovere i tag <Proxy *> & <Location /> per quel target e sostituirlo con DocumentRoot /var/www/node-example.com - il percorso statico per index.html

+0

Ho provato a utilizzare due tag virtualhost in precedenza, ma non funzionava ... Scoprendo che mi sono dimenticato di impostare "NameVirtualHost *". Grazie per la risposta però! – olke

+0

Sì, è un must per la configurazione di lavoro :) – drinchev

+0

@olke dovrebbe contrassegnare accettato ... – Pete

Problemi correlati