.NET, NGINX, Kestrel, and React with a Reverse Proxy on Linux Ubuntu

A bare-bones, 5 step tutorial.

Image for post
Image for post

Background: A Use Case More Complex than the Tutorial

Assumed Environment (Important: Please Read!)

Step 1 — Extend the NGINX Configuration for mysite.com to Include a Reverse Proxy

location /my-first-dotnet-app/ {  proxy_pass http://localhost:1234/;}
sudo service nginx restart

Step 2 — Configure the Default Kestrel Port for the .NET Application

"Kestrel": {  "Endpoints": {    "Http": {      "Url": "http://localhost:1234"    }  }}

Step 3 — Remove HTTPS Redirect from the .NET App

app.UseHttpsRedirection();

Step 4 — Setup React for the Correct Path with the package.json Homepage Directive

"homepage": "https://mysite.com/my-first-dotnet-app",

Step 5 — Create a Service File to Run the .NET Project

dotnet publish --configuration Release
MyFirstDotnetApp/bin/Release/net5.0/publish/
Description=My First Dotnet App[Service]WorkingDirectory=/var/www/MyFirstDotnetApp/bin/Release/net5.0/publish/ExecStart=/usr/bin/dotnet /var/www/MyFirstDotnetApp/bin/Release/net5.0/publish/MyFirstDotnetApp.dllRestart=always# Restart service after 10 seconds if the dotnet service crashes:RestartSec=10KillSignal=SIGINTSyslogIdentifier=my-first-dotnet-appUser=rootEnvironment=ASPNETCORE_ENVIRONMENT=ProductionEnvironment=DOTNET_PRINT_TELEMETRY_MESSAGE=false[Install]WantedBy=multi-user.target
/etc/systemd/system/my-first-dotnet-app.service
sudo systemctl enable my-first-dotnet-app.service
sudo systemctl start my-first-dotnet-app.service

Questions, Comments, Something Didn’t Work?

Written by

https://chrisfrew.in 👨‍💻Full Stack Software Engineer 🏠Austria/USA 🍺Homebrewer ⛷🏃‍Outdoorsman

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store