0

I am already running a php based wordpress website on my Azure Ubuntu 16.4 VM. now I also want to run a NodeJS website on same server under different domain name . How can I achieve this.

I know if both websites would be PHP or both would be .Net then I can do URL rewrite in apache or IIS , but here NodeJS use its own port and web server.

I am not sure if this works in Azure VM as We have to create inbound and outbound rules from azure portal to open ports of Azure VM. Apache and Node.js on the Same Server

Community
  • 1
  • 1
Abhi
  • 5,501
  • 17
  • 78
  • 133

1 Answers1

1

Yes, the answer of Apache and Node.js on the Same Server also works fine on Azure VM.

Generally, you can refer to the following steps:

  1. Enable the 80 port inbound rules of your Azure VM.

  2. Install proxy_module of apache2 in your Azure VM, via command a2enmod proxy proxy_http

  3. config the Virtual Host in apache configuration file, E.G. as default,

    run sudo vim /etc/apache2/sites-available/000-default.conf, and modify as:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /home/gary
        ServerName <vm_name>.cloudapp.net
        <Directory /home/gary>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride All
               Require all granted
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
        ProxyPass /node http://localhost:1337
        ProxyPassReverse  /node http://localhost:1337
    </VirtualHost>
    
  4. Restart the apache service: sudo service apache2 restart

  5. Start node server.

Then, directly browse your VM like via <vm_name>.cloudapp.net will browse the PHP site in the configured directory, and browse via <vm_name>.cloudapp.net/node will browse the node application.

Community
  • 1
  • 1
Gary Liu
  • 13,758
  • 1
  • 17
  • 32