I was curious, how hard it is to use them to host web applications built using .NET Core?
The thing with .NET Core web apps is that you need a reverse proxy to serve the app, which runs in Kestrel. In this part I will be using Nginx as a reverse proxy and will try to do that with both Amazon Linux 2 and Ubuntu.
The plan for each OS is:
- spin up EC2 instance (don't forget that security group should allow SSH and HTTP)
- install and configure Nginx
- create and run .NET Core web application
Install Nginx on Amazon Linux 2
It appeared that yum cannot install Nginx, since it cannot find it in repositories he has by default. After short googling, I came up with the decision to add the following repo:sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-$(rpm -E '%{rhel}').noarch.rpmAfter that, it possible to use yum to install Nginx:
sudo yum install -y nginxAdd to boot sequence:
sudo systemctl enable nginxStart Nginx service:
sudo systemctl start nginxAnd now it is up and running (check out in browser).
Install Nginx on Ubuntu
Easy:
sudo apt-get update sudo apt-get install -y nginxAdd to boot sequence:
sudo systemctl enable nginxStart Nginx service:
sudo systemctl start nginx
Nginx configuration
You need to add reverse proxy configuration for your domain:sudo nano /etc/nginx/conf.d/default.confI used this:
server { listen 80; server_name yourdomain *.yourdomain; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $http_host; proxy_cache_bypass $http_upgrade; } }and that required a small change in Nginx config to allow such a long host names, since 'yourdomain' would typically resemble something like 'ec2-34-244-132-120.eu-west-1.compute.amazonaws.com'. Open config:
sudo nano /etc/nginx/nginx.confand add\change the option in http section (not necessarily 1000 - use whatever works for you):
server_names_hash_bucket_size 1000;Check Nginx configs:
sudo nginx -tRestart Nginx:
sudo nginx -s reload
Create and run .NET app
Creating net core app is easy:
sudo mkdir /var/netcoreapp cd /var/netcoreapp sudo dotnet new mvcNow let's damonize the web app. Publish it:
sudo dotnet publish --configuration Release --output binAnd create deamon config for it:
sudo nano /lib/systemd/system/netcoreapp.servicewith the content as follows:
[Unit] Description=.NET Core App After=network.target [Service] WorkingDirectory=/var/netcoreapp ExecStart=/usr/bin/dotnet /var/netcoreapp/bin/netcoreapp.dll Restart=on-failure SyslogIdentifier=netcoreapp Environment=ASPNETCORE_ENVIRONMENT=Production Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false [Install] WantedBy=multi-user.targetNext, reload deamons:
sudo systemctl daemon-reloadEnable new deamon and start it:
sudo systemctl enable netcoreapp sudo systemctl start netcoreappChecking status is easy:
systemctl status netcoreappIf the deamon started successfully, open browser - your app is already running!
8 comments:
YOU HAVE SHARED BEST VALID INFO,KEEP POSTING.
<a href="https://www.vcubesoftsolutions.com/power-bi-training-in-hyderabad/>power Bi in kphb</a>
Really awesome blog your blog is really usefull,keep posting.
python full stack in kphb
I am very impressed with your post because this post is very beneficial for me and provide a new knowledge to me.devops training in hyderabadkeep sharing.
nice blog keep posting!
Your blog always provides a fresh perspective and inspires meaningful conversations
web Designing training near me
power bi institutes in hyderabad
Really awesome blog your blog is really usefull,keep posting.
devops-training-in-hyderabad
Veery nice blog you have here
Post a Comment