0

I'm currently running a web server with Ubuntu 16.04, serving up a Wordpress site, using LAMP stack and LetsEncrypt SSL to encrypt the website. I'd like to be able to run an Angular app with the MEAN stack on the same server, using a sub-domain.

Here are my Apache files right now running in my sites-enabled folder.

000-default.conf

<VirtualHost *:80>
        ServerName www.example.com
        Redirect permanent / https://example.com/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

example-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
        ServerName example.com
        ServerAdmin [email protected]
        DocumentRoot /var/www/example
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/example>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
         </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
ServerAlias www.example.com
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
</VirtualHost>
</IfModule>

Is it possible to accomplish what I want? If so, how?

1
  • Setup an Apache vhost for the subdomain and configure it to use node as the backend for a reverse proxy.
    – Sven
    Nov 28, 2018 at 14:34

1 Answer 1

0

It can be done. However, you can't bind two listeners on to the same port and device.

The easiest method is to serve the node.js app through apache.
First, be sure to enable mod_proxy in httpd.conf or another conf file. Then create a new virtualhost for your subdomain, that points the the port the node.js app is listening on.
For example: (assuming your node.js app is listening on port 8080):

<VirtualHost *:443>
    ServerName mysub.domain.com
    ProxyPreserveHost On

    # proxy settings to route to node.js
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass "/" "https://localhost:8080/"
    ProxyPassReverse "/" "https://localhost:8080/"

    # ssl settings
    Include /etc/letsencrypt/options-ssl-apache.conf
    ServerAlias www.example.com
    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem

</VirtualHost>

This will pas all traffic through Apache to reach the node.js app.
If you are not running ssl on the node.js app, you should use port 80 and http:// for this virtual host.

<VirtualHost *:80>
    ServerName mysub.domain.com
    ProxyPreserveHost On

    # proxy settings to route to node.js
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass "/" "http://localhost:8080/"
    ProxyPassReverse "/" "http://localhost:8080/"

</VirtualHost>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .