1

I am learning the fundamentals when it comes to developing and deploying MEAN stack applications, so please correct any part of this if it's wrong. I'll explain my current setup, and what I'm trying to do.

Setup

I have a single AWS EC2 instance that I wish to use for all of my MEAN stack apps, as well as a Load Balancer that I'm mainly using to handle SSL requests. The EC2 instance is running Ubuntu, and I have installed on it Node and Nginx.

Right now I only have one Node app, which is running on port 3000. The Nginx server (the configuration file for which I will paste down below) is listening on port 4000 and redirecting the requests to the node app on 3000. Finally, the Load Balancer is configured to accept requests from ports 80 and 443 and direct them both to the Nginx server at 4000. So, basically:

HTTP (80) ----
              |
               --> Load Balancer --> Nginx (4000) --> Node App (3000)
              |
HTTPS (443) -- 

Here is the full Nginx configuration file I am currently using at the moment:

user ubuntu;
worker_processes 1;
pid /run/nginx.pid;

events {
    worker_connections 1024;
    # multi_accept on;
}

http {
    server_names_hash_bucket_size 64;

    gzip on;
    gzip_comp_level 6;
    gzip_vary on;
    gzip_min_length  1000;
    gzip_proxied any;
    gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_buffers 16 8k;

    upstream vidzyApp {
        server localhost:3000;
    }

    server {
        listen 4000;
        server_name <domain>.com *.<domain>.com;

        root    /home/ubuntu/server;

        error_page 404 /default.html;
        error_page 403 /default.html;

        location / {
            proxy_pass http://vidzyApp;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    }
}

The Node app I am running is an app made from following a tutorial and is called Vidzy. If I visit my website over HTTP or HTTPS, right now, everything is working beautifully. However, here's what I want to do.

The issue

Basically I want to be able to have multiple MEAN apps running that are accessible via different URLs on the same domain. For example, to access Vidzy, I would want to visit http://[domain].com/vidzy/.

I tried modifying the Nginx config file myself in various ways, but nothing works right. The first thing I tried was changing the location part of the server to be /vidzy instead of just /. But doing that, the app seems to freak out pretty badly.

I'm still trying to understand how the components of a MEAN app are interacting with one another. It looks like the issue occurs when trying to change the location to /Vidzy, it messes up the app in such a way where files located in the public folder of the app cannot be found with the new URL structure.

Is what I'm doing even feasible at all? And if so, how much of this am I screwing up?

1
  • I am not familiar with MEAN stack, but you might try proxy_pass http://vidzyApp/; to ensure that location /vidzy/ maps to the root of the Node app. Ensure trailing / on both URIs. Jan 22, 2016 at 10:21

1 Answer 1

0

You're on the right track.

You need a server { ... } block for each virtual host. The server_name is used to decide which which server block applies to which hostname(s) in the incoming request.

The first one should be set up as the one that handles unexpected requests, and you'll probably want to make this return a generic error page with 503 Service Unavailable or 404 Not Found since it's a request you won't be interested in processing (a search spider, a bot, or the result of someone else's misconfiguration). In the first server { ... } block:

listen 80 default_server;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.