https://github.com/adampaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux
Dotnet Core MVC web app running on Linux using Docker and nginx as a reverse proxy
https://github.com/adampaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux
azure azure-web-app-service dockerfile dotnet-core nginx nginx-proxy
Last synced: about 2 months ago
JSON representation
Dotnet Core MVC web app running on Linux using Docker and nginx as a reverse proxy
- Host: GitHub
- URL: https://github.com/adampaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux
- Owner: AdamPaternostro
- Created: 2018-10-25T20:57:58.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-25T21:41:45.000Z (almost 7 years ago)
- Last Synced: 2025-04-05T12:33:03.377Z (6 months ago)
- Topics: azure, azure-web-app-service, dockerfile, dotnet-core, nginx, nginx-proxy
- Language: C#
- Homepage:
- Size: 568 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## How to use nginx as a reverse proxy in a linux docker image hosting a dotnet asp core web app
This is some sample code to create a dotnet core web app, install nginx, configure nginx as a reverse proxy and provide a warmup script so the container is not added to the Azure web app load balancer until the application is warmed up. This application will not have a long warm up since it is just a sample. To understand Azure and site warm-ups please read reference this: https://github.com/AdamPaternostro/Azure-Tomcat-Web-App-Container
### How to run this sample
```
Software: Install Docker
Software: Install .NET Core 2.1.5
Create directory: mkdir azure-web-app-nginx-reverse-proxy-dotnet-core-linux
Change directory: cd azure-web-app-nginx-reverse-proxy-dotnet-core-linux
Create directory: mkdir nginxproxy
Change directory: cd nginxproxy
Create .NET code: dotnet new mvc
Restore Packages: dotnet restore
Change file: Add .UseUrls("http://*:5000/") to the Program.cs
WebHost.CreateDefaultBuilder(args)
.UseUrls("http://*:5000/")
.UseStartup();
Build: dotnet build
Run locally: dotnet run
Open a browser and view: http://localhost:5000/
Ctrl+C to quit the dotnet run
Publish locally: dotnet publish
Change directory: cd ..
Download Files: By hand or wget these 3 files (Dockerfile, start-server.sh, azurewebsites.net)
wget https://raw.githubusercontent.com/AdamPaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux/master/Dockerfile
wget https://raw.githubusercontent.com/AdamPaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux/master/start-server.sh
wget https://raw.githubusercontent.com/AdamPaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux/master/azurewebsites.net
Build Image: docker build -t nginxreverseproxydotnetcorelinux .
Run Image Locally: docker run --rm -it -p 80:80 nginxreverseproxydotnetcorelinux
Edit Hosts file: When you go to localhost you will see nginx default page
Mac: /private/etc/hosts
Windows: C:\windows\system32\drivers\etc\hosts
ADD: 127.0.0.1 docker.azurewebsites.net
Now load docker.azurewebsites.net and you should see your app
Ctrl+C to stop
Clean Up Docker: docker stop $(docker ps -aq) | docker rm $(docker ps -aq)
Upload to Azure ACR:
Login Registry: docker login REMOVED.azurecr.io --username REMOVED --password <>
Tag: docker tag nginxreverseproxydotnetcorelinux:latest REMOVED.azurecr.io/nginxreverseproxydotnetcorelinux:latest
Push: docker push REMOVED.azurecr.io/nginxreverseproxydotnetcorelinux:latest
```### What I changed in the "dotnet new web" app
In the file nginxproxy.csproj make sure your Target Framework is 2.1
```netcoreapp2.1
```
In the program.cs make sure you have the UseUrls line:
```
WebHost.CreateDefaultBuilder(args)
.UseStartup()
.UseUrls("http://*:5000/")
.Build();
```### Notes
Since your application name will be different you will mostlikely need to change:
* You will need to change line 4 in start-server.sh
* https://github.com/AdamPaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux/blob/master/start-server.sh#L4
* You will need to change line 10 in start-server.sh
* https://github.com/AdamPaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux/blob/master/start-server.sh#L10
* Publish release mode: (dotnet publish --configuration Release)
* You will probably build in Release mode so you will need to change line 83 in the Dockerfile
* https://github.com/AdamPaternostro/azure-web-app-nginx-reverse-proxy-dotnet-core-linux/blob/master/Dockerfile#L83