简体   繁体   中英

How do I run more than one asp.net core application on Nginx server

I want to run two or more asp.net core applications on the same server. But the ip and port they use are 127.0.0.1:5000.

The point of a reverse proxy like nginx is that you can host multiple applications on it, regardless of what internal port they use. So you can easily host applications on ports 5000, 5001, 5002, etc. and then make nginx expose all those applications on different domains on port 80, or even as subpaths of the same domain (if the applications are set up properly to support that).

So an nginx configuration could look like this:

server {
    server_name host1.example.com;

    location / {
        proxy_pass http://localhost:5000/;
        # …
    }
}

server {
    server_name host2.example.com;

    location / {
        proxy_pass http://localhost:5001/;
        # …
    }
}

server {
    server_name host3.example.com;

    location / {
        proxy_pass http://localhost:5002/;
        # …
    }
}

This would host three different applications, using internal ports 5000, 5001, and 5002, on the three different subdomains host1.example.com, host2.example.com, and host3.example.com.

Of course, this requires you to actually run your applications on different ports. You can use the ASPNETCORE_URLS environment variable to set the url dynamically at which the app is being hosted, eg using:

$ ASPNETCORE_URLS=http://localhost:5001 dotnet run

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM