SoFunction
Updated on 2025-04-11

nginx configures multi-domain name sharing server port 80

Multiple domain names, such as two domain names, actually share a server (meaning that the domain name is resolved to the same IP), one domain name is (can be or), and the other domain name is (can be or) to point to a server together. The ports bound to the application that provides services on the server are different, such as:

localhost:1234  ->

localhost:5678 ->

Configure nginx files so that the browser passes or accesses different "websites" (makes visitors feel that this is not the same server). In fact, this application scenario can be distinguished by domain name + port, so that the service programs on the same server run on different ports. However, in this way, user access needs to be done through: port 1 or: port 2, which makes the user feel a little strange. The best way is not to let the user add the port, pass or access directly. What developers need to do is to share a 80 port through nginx and distribute it to service programs on different ports on the same server.

The core is configuration implementation:

http{

    server {
        listen       80;
        server_name  ;
		
		location / {
            proxy_pass   http://localhost:1234;
        }
    }
	
	server {
        listen       80;
        server_name  ;

		location / {
            proxy_pass   http://localhost:5678;
        }
    }


    ...
}

This is the article about nginx configuring multi-domain names to share server 80 ports. For more related content on nginx configuring multi-domain names, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!