mcadio
mcadio

Reputation: 769

Create test server using IP address for 2 apps

I want to deploy a test server using a digital ocean droplet. I've got it up but don't know how to setup the nginx sites-available to work correctly. I've got two apps running on the server:

/var/www/html/new_app (Should use port 8080) /var/www/html/old_app (Should use port 8081)

I don't know what I'm doing here, and have tried looking at examples but they all use domain names and not the localhost or standard IP address.

What I have currently:

/etc/nginx/sites-available/default

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html/new_app;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

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

/etc/nginx/sites-available/old

server {
        listen 80;
        listen [::]:80;

        root /var/www/html/pottstown_old;
        index index.html index.htm index.nginx-debian.html;

        server_name _;

        location / {
                proxy_pass http://localhost:8081/;
        }
}

I tried adding another file for the old site, but it gave me an error:

nginx: [warn] conflicting server name "" on 0.0.0.0:80, ignored nginx: [warn] conflicting server name "" on [::]:80, ignored nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

However when I call up the IP address, I get Failed to open page. How do I set this up to send requests for 64.225.60.54 to the 8080 port which serves the new app, and requests for port 8081 to the old_app?

Do I just need one server with two location blocks? I just don't get it.

Upvotes: 0

Views: 327

Answers (1)

Timo Stark
Timo Stark

Reputation: 3071

Not sure what kind of application you want to host but in general.

In case you need two different ports for your applications you should create two server blocks.

App NEW - listen 8080

server {
   listen 8080;
   listen [::]:8080;

   root /var/www/html/new_app;
   index index.html index.htm;
}

App OLD - listen 8081

server {
   listen 8081;
   listen [::]:8081;

   root /var/www/html/old_app;
   index index.html index.htm;
}

Upvotes: 0

Related Questions