Answer a question

I installed Nginx on my server (my server uses WHM). And on this server has two accounts. Each account will run a server a NextJS site and each account has its own domain.

Site1 will run on port 3000

Site2 will run on port 3004

What I want to do is:

I want to access domain1 I see the content of my site1 in NextJS that runs on localhost:3000

And when I access domain2 I see the content of my site2 on NextJS running on localhost:3004

I tried to do a Nginx implementation for site1. But when I accessed it I saw a Cpanel screen, and the url was dominio1/cgi-sys/defaultwebpage.cgi

Here's the Nginx implementation I tried to do:

server {
    listen 80;

    server_name computadorsolidario.tec.br www.computadorsolidario.tec.br ;

    location / {
        proxy_pass http://localhost:3004;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
    }
}

So how do I do this setting for nginx to have this behavior? And I'm changing the correct file?

Note: I created the configuration file in /etc/nginx/conf.d/users/domain1/domio1.conf And within /etc/nginx/conf.d/users have several configuration files with the name of the accounts you have on the server. (They are already implemented.)

Answers

Try

  server {
    listen 80;
    server_name www.domain1.com;
    proxy_pass http://127.0.0.1:3000;
  }
  server {
    listen 80;
    server_name www.domain2.com domain2.com;
    proxy_pass http://127.0.0.1:3004;
  }

Each domain listens on same port and reverse-proxies to local network on the ports you specify. To differentiate between hosts, specify the server_name field.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品

更多推荐