Question

Deploy a Node.js application in Apache server with php sub directory

I am running an Ubuntu 18.04 server with apache2.4 and I am trying to deploy a node.js application with a PHP Api on this same server.

I have successfully configured the server to read my node.js application on port 80 but I am not able to configure a sub directory to load php. I want to deploy my application in such a way that calls to mydomain.com are served through node.js while calls to mydomain.com/api are served by a php API.

I have configure my 000-default.conf as follows but I don’t know exactly how to remove the php sub directory from being rendered by node because now, everything called via port 80 is rendered by node.

<VirtualHost *:80>
    ServerName mydomain.com

    DocumentRoot </path_to_app>
    <Directory />
    Options -Indexes +FollowSymlinks
    AllowOverride None
    Require all granted
    </Directory>

    ProxyRequests Off
    ProxyPreserveHost On
    ProxyVia Full
    <Proxy *>
    Require all granted
    </Proxy>

    <Location />
        ProxyPass http://127.0.0.1:8080/
        ProxyPassReverse http://127.0.0.1:8080/
    </Location>

    <Directory path_to_app/api>
         DirectoryIndex index.php
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

As the Locaiton is set to / it catches all of the requests.

What you could do instead is remove the Location directive and use the following configuration instead:

Alias /api /var/www/html

ProxyPass /api !
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://127.0.0.1:8080/

That way your /api endpoint will be excluded from the reverse proxy, and it will serve the content of the /var/www/html folder.

Hope that this helps.

Regards, Bobby