简体   繁体   中英

How to bind two domain names to two different websites(php and nodejs) running in same Azure Ubuntu VM?

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

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, EG 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM