Linux (Basics): 4 of 4 - Configure Apache as reverse proxy to host .Net Core WebAPI on Linux Ubuntu

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome to the solution architectural and we've got a ton of things we have to cover inside this video so let me just take you through the list install.net core runtime libraries and as well as the dotnet sdk on linux then install the Apache runtimes on Linux and then configure the firewall settings for Apache then we're gonna install open SSH to allow file copies from Windows machine to the Linux machine they were going to configure the Apache on the sites available for our web application or Web API then we're gonna make some code changes and inside the code before we copy that code to Linux and then we copy the code I'm using FileZilla to copy the code from windows from my Windows machine to the Linux Ubuntu virtual machine and then we can now run in a release on the Linux of winter machine and then we're gonna install and I know this is a lot a lot of things in this video but this is all necessary to be able to run this then install supervisor I'm using supervisor to run my web api and to monitor the web api and then we're gonna configure and copy all the files to a w-w-w folder inside linux and we'll do some some settings and modifications inside there you copy the files over we configure the in supervisor for our web api and then we'll taste we'll start it and taste and run it on the Linux machine as localhost and then I'll go back to my Windows machine and then I taste it from postman and run it from my Windows Windows machine so that is a lot to take in I apologize for a long video but this is necessary to be able to run your wit API on Apache on Linux so let's jump into this so inside your Linux virtual machine we want to now install the runtime of dotnet core 3.1 and I first going to just copy the paste inside here like the Microsoft packages specifically for eighteen point four you need to have the runtime before you can install Apache that's the first thing we do and then install the Microsoft production packets well I'll leave the link below in what needs to be installed okay admin admin password and then let me show you the following instructions is the repository and then update and then install the H the transport HTTP and then we're installed run the update again and then install the asp.net core runtimes so I'm gonna copy and paste all of this and just run it okay I'm in Linux if you run those commands and then install the.net runtime and I will post this video as soon as it's done come back to you and the last one here is a SP not Nico runtime I need to press in today and you want to say yes you want to install this continue and I'll post and come back when it's done and it's complete install then let's clear the screen let's just run sudo apt update and I'm gonna install this original minister install the SDK don't need SDK because you cannot build and release the package on site your Windows machine if you're gonna release to a Linux machine so you have to build it on Linux machine itself and that's why I'm gonna install both they don't need SDK and it's 3.1 so yes and enter and I'll post this video and come back when it's done ok so I'm like clear the screen now next step will be to install Apache ok so let's prepare this student at not good but anyway let's install apache2 yes now let's check our firewall settings on this you have w see the app list and you'll see that Apache Apache full secure is already now part of your firewall list what women do is we want to with a UAW allow allow Apache to the firewall now let's check firewall status and you've got this is for my sequel the 3:06 and Apache is for allowing Apache to be called from external ok now let's check our status of our Apache server it's just CTL stateless hg2 ok and you can see Apache is up and running and the next step will be for us now to do our configuration for for the.net core application is be application ok so let's edit sudo I guess nano you can use Verma if you have it installed so we've got your Apache config file there so we want to add the server name which is our localhost we can just add it anywhere inside here just to add server name to localhost in this file and save okay let's clear the screen and let's run a sudo apt update first always do that and then let's install open SSH so yes enter now pause here and come back when it's done okay so let's just check system CTL I'd stick to check the status of is this page this is H okay that is up and running and we won't allow through our firewall ufw allow SSH so that will add more so let's just check how status of our Farwell we've got a lot of things that we have on there now we've got port 22 because that is what SSH allows we've got apache and we've got our my sequel server an important configuration setting we have to set up for apache is the following so sudo nano if i can't i pasted to the manor that's right et Cie apache two sites available and when you type in this this will create an empty screen for you so you just need to grab the information that i leave in the description the link below you call it your you know I'm trying to be consistent so I say my sequel wave API daaad config when you open this yours will be empty i've already created mind so i just want to show you what you need to put in here and this is only for testing purposes so when you do actually want to go production you want to use this all you want to use port 443 and you want to use certificates and party ROM but for just home testing and seeing if you can get your linux up and running I think it's very simple you add these few lines the proxy reserved host on and proxy pass is 127 dot 0 dot 0 dot 1 and your our port we use is 5000 if you have a different port then you need to put that fourteen-year and the proxy reverse proxy pass is exactly the same and in your server name I just put my server name in say my sequel Web API the same as it's my application name alias I just added a little is every dot I don't think this is really important and then you have a log file for your application the airlock fault specifically the lock on the patchy side so Apache will lock any application problems here for you and in your custom lock in your close and you save this so - already saved and then you need to restart Apache then you just say sudo systemctl Apache to restart and then you can check your status you have to check your status if it's an everyday do you need to go check out your error logs because then you might have done Inc incorrect configuration on that file there might be a problem inside that config file and just go check to see if you copied everything correctly inside there after you've done this then we'll do some company jaysus in our code so we're back inside our visual studio code into our code I'm gonna show you a few changes that you need to make inside here to be able to run your web api on linux using apache as your as your reverse proxy so i'm just gonna show you the few changes that I make remember I'm gonna leave the code link in the description below so you can go and reference the code inside your startup dos seus you need to add this piece of code here so this is to forward to the reverse proxy so you need to add these this piece of code inside you start up the CS inside the configuration method the next change add this piece of code to your configuration service method it's service or configuration forward here this option to allow your proxy and you can put your IP address of your Linux server in here okay I had some issues with my IP address because I shut down my linux server when I started up at a different IP address okay so the next step is to go to program that CS and inside here in your create host Boulder and if you use 3.1 you'll have the same setup as me if you use an older version that will use a webhost builder but we'll use just to create host AHS Boulder you just add the following next to the web Boulder you add use kestrel which is used to expose the web api from your application and use the I always add this use content route current directory this will be important if you start using things like you need to save the file or things like that and then if you decided on what port to use you add this part use URLs so it can be any IP address but only for port 5000 you can use any port unless ok don't use for 443 and don't use port 80 this is for your internal hosting your proxy to be able to host this internally and then your Apache reverse proxy will pick it up and I'll show you how to configure that so these are the changes that you have to make inside your web application before you deploy it to your next machine ok so now we want to copy our application a project files over to the Linux machine I'm using as you know fonsella so I've added the IP address in yeah username and password port 22 normally and you just click connect and it will open up like that inside so what you're seeing on the right hand side here is Linux your Linux machine and I'm gonna create a just a directory from my web application it's just gonna call it my sequel Web API and go inside there and I don't want to never copy the bin folder over because that's DLL sets running on Windows you don't do that so you can only copy the controller the model in copy your properties or JSON files your project file your program is slowed up and and that I'm just going to drag and drop that over and that will create my will be my folders on on Linux now let's go back to limits okay inside Linux just run Alice and you see they my sequel Web API Cindy and let's change directory to my sequel right behind Alice and this is all the files inside there so now we'd run dotnet publish configuration release so what this will do is this will just create where I am remember you need to be inside your folder where your project files or copy to and that's gonna create a release you want to do this on Linux because it's using the Linux runtime libraries to create your code your executables for you and I'm going to dispose this and when it's done I'm pause okay so it has created my and it's under this folder this is with my dll sore and my publish files in inside there I'm just gonna clear this quickly and I want to install a tool called supervisor and so yes and supervisor will help you run your application for you and easier to publish so I use supervisor even on in Jenks as well but you can use it on Apache as well I'll pause and come back when it's done okay so supervisors installed now I want to go to you I said to you that we want to publish it to www so when I go in today I might need to give myself access inside a but I'm gonna make a directory in K directory oh oops my sequel wave IP I remember we should be going to deploy it there and I need to act myself some permissions okay so after several tries I use sudo shown the admin which is my admin user that I logged in and give myself access T so I created the folder there so I have now full rights on this it's just go to CD my little with API and I'm going to just give myself full access here to this as well can't spell today okay so I am the owner D and I want to also create some errors day to add modifications to my steeple Web API just give more rights to that and then let's go back to my sequel Web API so I'm just going now back to away my cody's and we're gonna do the copy okay let's clear screen and if I remember correctly now memory serves me right is CPUs for copy and my sequel wait break the I hope I remember that correctly then the lease neat core app 3.1 I think publish and store and let's copy that to my boy don't EE doubt whip sequel with API its app that works and I don't have the correct file let me just go check it up gets back yeah so I think I made a little bit of a boo-boo here let me just copy and this can you believe it it's just a upper case here can you believe it 2 vol W dot my sequel Web API the intern and that should have copied everything through to that all the day now let's copy this and let's go to CD and inside that folder now and everything is inside see all your D allows and everything is inside here ok now we want to create a config file for running our application on supervisor remember we installed supervisor for the reason to run application you can run it as a service I find that supervisors just use works much better for me so etc that's think it's just um dot d and my sequel with API dot country so this is your application name that config and I've already created this I'm just gonna show you what I've done so when you type in that sudo nano command you will come up with the empty screen here don't worry about it make just make sure that you've got it et Cie supervisor config dot d and your application name dot config now you need to change a few things here your program name my sequel Web API then you can just copy and paste this in the link down below I will leave this in in the files that I upload to get up so you've got your command user been donate make sure that this is where your dotnet libraries or implemented or installed and then you've got your application like it is your DLL name of your application so if your ordeal application name is my sequel Web API DLL that's exactly what you need to put in there the directory rate that is running from and we created this it can be anything as long as it runs off www or to start true or to restore true and I created a lock folder you don't have to create an LOC folder separate one but you need to have a lock file so you can check in any errors inside your error log file and you also have an outfall which is when the application runs is it will just anything that comes out of the debug window will be locked inside there and your environment you're running on is asp net core environment production user is important WWE data and stop signal int stop a script true and kill a scripture and then you just save this okay so I'm off already sized mine now you need to check your status of your supervisor size sudo service supervisor status so mine is running you can see that you have to stop it after you created that you have to stop your service service and if you're under status now you'll see it stopped okay so it's inactive and then you need to start it okay so when you start your supervisor your application will kick in as well and you can look at your lock files to if there's any errors to see what is happened actually and i've actually fixed an error earlier and that's why i already created my my config file now it's gonna be important for us to go taste to see if it works so there's two two things internally what you can do you can just go to your say you've run on Linux go to your Firefox web browser or what Brit browser you put in your IP address you can put in your localised your port name your port is 5000 and products okay and that will run and we'll come back with my data from my sequel database when and I'm we gonna switch now to postman and we're gonna run it from thee okay inside postman now now I'm on my Windows Tin Machine and I'm gonna call the Linux machine but a mistake that I made is I make mistakes as well is I added the port in here remember Apache will listen on the localhost and it will listen on the server itself and the port already allows access to this IP address you have to take out the port to be able to call that IP address and just called gluten products and then we sent that through and this is what we got back so let's taste and add a a 1/2 hour it's erased post ok what's gonna this is the wrong one it's supposed this one and I'm going to go to my body here and let's add one safe for just to make sure that we don't have any clash database and this will post and we'll come back with ID 8 and then let's run this again and they've got it we've got our whip API running on Apache on Linux successfully and we'll come back and then the next few videos we'll create the MVC whip you I thank you very much for watching guys and please come back next time and I hope you enjoy this video so far
Info
Channel: The Solution Architect
Views: 4,239
Rating: undefined out of 5
Keywords: apache, linux, ubuntu 18.04, .Net Core 3.1, WebApi, C#
Id: WUAhKhWgsIg
Channel Id: undefined
Length: 29min 43sec (1783 seconds)
Published: Wed Apr 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.