0

I have two domains linked to the same server: domain1.com and domain2.com.

When I try to configure two separate websites using these domain names, I encounter an nginx error 500.

I have set up nginx for the first domain. I created the configuration file in sites-available and linked it to sites-enabled.

Here is the domain1.conf file that is stored in sites-available and linked to sites-enabled:

server {

server_name domain1.com, www.domain1.com;
listen 80;

    location / {
        proxy_pass https://somehost/;
        proxy_redirect default;
                }
}

server {

server_name domain1.com, www.domain1.com;
listen 443 ssl;


    location / {
        proxy_pass https://somehost/;
        proxy_redirect default;
                }

ssl_certificate crt;
ssl_certificate_key key;
}

It works perfectly. Also, with this confinguration file, when I'm trying to access domain2.com it shows me the domain1.com content.

And when I'm trying to create domain2.conf file in sites-available, and link it to sites-enabled, I'm recieving the nginx error 500 on both sites.

domain2.conf:

server {

server_name domain2.com, www.domain2.com;
listen 80;

    location / {
        proxy_pass https://someotherhost/;
        proxy_redirect default;
                }
}

server {

server_name domain2.com, www.domain2.com;
listen 443 ssl;


    location / {
        proxy_pass https://someotherhost/;
        proxy_redirect default;
                }

ssl_certificate crt;
ssl_certificate_key key;
}

Also, when I'm trying to cat both files in a single domain1-2.conf file, I got the same error.

There is no other files or links in sites-available and sites-enabled. The server is ubuntu20.04 I need to work multiple sites on single server. What am I doing wrong?

UPDATE:

I'm receving no errors. Only alerts. Here is the string that writes in error.log, when i'm trying to access domain2.com from browser.

 2023/06/19 13:07:00 [alert] 107176#107176: *110116 768 worker_connections are not enough while connecting to upstream, client: 123.456.789.000, server: domain1.com,, request: "GET / HTTP/1.0", upstream: "https://123.456.789.000:443/", host: "domain1.com"
2023/06/19 13:07:01 [alert] 107176#107176: *110880 768 worker_connections are not enough while connecting to upstream, client: 123.456.789.000, server: domain1.com,, request: "GET /favicon.ico HTTP/1.0", upstream: "https://123.456.789.000:443/favicon.ico", host: "domain1.com", referrer: "https://domain2.com/"
2
  • Firstly, server_name does not take a comma separated list, it takes a space separated list, so you are specifying some domain names with a trailing ,, which is why domain2.com is not recognised. Secondly, look at the error log for more details. Jun 19, 2023 at 9:40
  • Well, those commas was the source of issue, actually. Thanks.
    – Antareo
    Jun 19, 2023 at 10:28

1 Answer 1

0

Thanks to @Richard Smith comment. The problem was in comma-separated server_name directives.

nginx -t doesn't showed me this error.

Seems like nginx read all of server {} directives from both files and ignore server_name directive, because the commas in there, and that's why I was getting error 500.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .