Is it possible to set up a clients side js powered web app and a php web app for the same URL

July 15, 2014 895 views

I've built an entire customer portal using a client side framework (meteor.js), but for the public facing portion of the website, I would like to build it in php (for SEO reasons). Ideally, what I would like to do is have a subdomain for the customer portal, for example, www.portal.mydomain.com. And for the public facing php powered portion of the site, just have the regular ULR: www.mydomain.com. Is it possible to set something like that up here on Digital Ocean? Would I need to set up two droplets?

1 Answer

You can definitely accomplish this on one droplet. You need to set up DNS records for both subdomains that point to the droplet's IP address. Check out this article for more information on how you can do that using DigitalOcean's DNS panel.

Then, you need to have you web server set to listen for both domains and proxy them correctly. Do you already have something like Nginx sitting in front of your meteor app? The Nginx would probably look something like:

# Standard Nginx/PHP setup serving www.mydomain.com
server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    server_name www.mydomain.com;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

# Proxy requests for www.portal.mydomain.com to the meteor app

# Upstream server listening on localhost port 
upstream app_server {
    server 127.0.0.1:58080 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    server_name www.portal.mydomain.com;

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }
}

Once you have that setup, you simply need to have your public landing page direct users to the right URL when they log in to the site.

Hopefully this points you in the right direction. If you've got any more specific questions, free free to ask!

by Assaf Gordon
Here's some documentation on how to set up and test DNS subdomains with DigitalOcean's DNS panel.
  • Is this same setup possible to do without sub domain? Such as domain.com/ <-- landing page and all other urls starting domain.com/anything will be the meteor app?

Have another answer? Share your knowledge.