Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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!
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.
If you have not explicitly defined a default_server the first server block is chosen. Since neither of your server blocks contain the www prefix the default server is used. You can capture the naked domain and the www explitly or you can capture naked and all subdomains like this:
server_name .domain1.com;
This comment has been deleted
The above answer was working for domain 1 and 2 redirecting to two nodejs services. But now i redirected 2 new domains to my D.O. server (e.g. domain3.com & domain4.com).
These domains still only resolve to the first server block.
After adding a new DNS record for both new domains and adding the names to server_name part of NginX, still domain 3 and 4 did resolve to the domain 2 block.
p.s. domain1 should ad up to domain3 and domain2 to domain4
I tried the following server name configurations:
server_name .domain1.com .domain3.com;
and
server_name domain1.com domain3.com www.domain1.com www.domain3.com;
and finally created 2 server parts, going to the same app and listening to the same port.