Question

How to use one droplet and one domain to host a few projects.

Thanks for looking.

I have a droplet running pm2 and nginx.

I have my react project running on the main domain all okay.

I am trying to host a few node projects on different ports and trying to access them by using for example, www.domain.com/project1 and www.domain.com/project two.

Below, I tried to route /domain to the main page as a test, but it is not working and says it cannot find it. I have hidden my domain name and its IP.

Could anyone shed some light on how I can achieve my outcome, or point me in the direction of someone who has written about it.

Many thanks

Russell


server {
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/DOMAIN/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/DOMAIN/privkey.pem; # managed by Certbot
    server_name www.DOMAIN.com;
    return 301 https://DOMAIN.com$request_uri;
}

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

        server_name DOMAIN IP;

         location /{
        # reverse proxy for next server
        proxy_pass http://localhost:3000; # your nextJs service and port
        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;

   }

         location /dashboard {
        # reverse proxy for next server
        proxy_pass http://localhost:3000; # your nextJs service and port
        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;

   }

        location /tweetyapi {
                # reverse proxy for next server
        proxy_pass http://localhost:3333;
        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;

        }
          

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there Russell,

I believe that you are on the right track. One thing that you need to keep in mind is that you can only have 1 service listening on a specific port. For example, as of the time being it looks like that your main service and the service that should be accessible at /dashboard are both configured to listen on port 3000.

You need to make sure that you have specified different ports and also you’ve specified the correct ports in the Nginx reverse proxy configuration.

Also if your applications are not expecting the sub folder in the URL, you could rewrite the requests to remove the subfolder as follows:

    location /dashboard {
        rewrite ^/dashboard/(.*)$ /$1 break;
        # reverse proxy for next server
        proxy_pass http://localhost:3000; # your nextJs service and port
        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;

    }

    location /tweetyapi {
        rewrite ^/tweetyapi/(.*)$ /$1 break;
        # reverse proxy for next server
        proxy_pass http://localhost:3333;
        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;

    }

Hope that this helps! Best, Bobby