Question

site-available vim default configuration to run two nuxt.js domains on one droplet

I want to run two nuxt.js domains on single droplet. I have configured everything but when I open the domain, nginx says 404 not found.

Npm run build works fine for both domains inside /var/www/domain1 and var/www/domain2 and I think issue is with the sites-available vim default configuration.

Here is my configuration:

server { listen 80; server_name domain1.com;

    location / {
            proxy_pass http://127.0.0.1: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;
    }

} server { listen 80; server_name domain2.co.in;

    location / {
    proxy_pass http://127.0.0.1:3000;
    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;
    }

}

I’m running domain1 on port 3333 and domain2 on 3000 sothat port issue does not occur. Do i need to change anything in site-available file?


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.

KFSys
Site Moderator
Site Moderator badge
March 22, 2023

Hey @aashaytrivedi1,

You need to create two Nginx configuration files. Basically, every domain needs to have his own configuration file.

So what you’ll need is :

Config file for domain1.com located in /etc/nginx/sites-available/

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

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

        server_name domain1.com www.domain1.com;

        location / {
            proxy_pass http://127.0.0.1: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;
        }
}

and another in the same direction for domain2.com

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

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

        server_name domain2.com www.domain2.com;

        location / {
            proxy_pass http://127.0.0.1:3000;
            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;
        }
}

That would mean you have two config files in /etc/nginx/sites-available/ -

  • /etc/nginx/sites-available/domain1.conf
  • /etc/nginx/sites-available/domain2.conf

Now to enable your config files you need to execute:

  1. sudo ln -s /etc/nginx/sites-available/domain1.conf /etc/nginx/sites-enabled/
  2. sudo ln -s /etc/nginx/sites-available/domain1.conf /etc/nginx/sites-enabled/

Restart Nginx and that’s it.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel