Resolve two domain names to different ports on the same server.
First, configure two domain names to resolve to the same server, and then install nginx.
Set two server blocks in nginx configuration file, with server_name as two domain names respectively, and then set their corresponding access ip and port number. Examples are as follows.