Configure Nginx Reverse Proxy

To configure Nginx to act as a reverse proxy you will need to edit the default site config.

sudo nano /etc/nginx/sites-available/default

This is a boilerplate config referenced from Microsoft:

server {
    listen        80;
    server_name   example.com *.example.com;
    location / {
        proxy_pass         http://127.0.0.1:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

After saving the configuration you can test that it’s valid:

sudo nginx -t

If the configuration file is valid you can reload Nginx and apply the new settings.

sudo nginx -s reload

Troubleshooting

If the service fails to start, you might get more insight by reviewing the logs.

sudo journalctl -fu Your_Service_Name.service

References

Host ASP.Net Core on Linux with Nginx:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/linux-nginx?view=aspnetcore-7.0&tabs=linux-ubuntu