Deploy Django with NGINX and Waitress on Windows Server 2019

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so this is going to be a quick tutorial on how to set up your tango web project with nginx to serve your static files I'll be using waitress as the server for Django so my web project is located on my github page so I will be linked in the description below but there are steps outlined for how to do this so I'm just gonna go to these steps so you can see that there's a heading here nginx and waitress so the first thing that I need to do before I begin setting this up is spend up a new VM I'll be using the Google platform you can use VirtualBox or whatever whatever is available to you but since I already have my VM running I'm going to open that up and I've had so I've gone went ahead and set up a couple of things the first thing I did was install Python I chose to use Python three seven seven I also downloaded and installed git bash onto this VM and Visual Studio code which will be needed in order to add a couple files so if we go down I'm just going to refresh this page alright so the first thing that we need to do is we need download and install nginx and we're going to save it onto just the C Drive so currently right now what's available under the mainline is version 1.1 9.0 so I'm download that and I'm just going to extract the contents we're going to copy this and like I said I'm just gonna paste it right on the C Drive that's basically it for now close this out the next step is to inside pot install Python and as I mentioned I already did that the three libraries that you need to install will be django open pie excel and waitress and the next step we need to do is edit our settings at pi there's there are essentially three settings that we need to do okay so the settings that we need to are the change that we need to make to our settings up pop out alright first to set the bug to false ad in a local host the name of your server i think mine is called see windows nginx and then you also want to copy the IP address to your VM and if you're just running this on your virtual machine box on your local machine you don't need to worry about this part okay so the next thing that we need to do is over here down below we need a chain we nee add a static route for our static files okay no we're just going to go ahead and run this line python management hi collect static so i'm going to open up go to my desktop open up my web project and right here i'm just going to type in CMD to open up a terminal i'm going to type in python magpie collect static and I don't have much CSS in this project so there's just gonna be the admin CSS and once he SS file for my own project which you can see here they're my up just one style CSS file okay so we have our settings updated we have our static collected the next step that we need to make is alright so we need go to the this directory nginx waitress and there is a comm file for that specifically for nginx so our three things that we need to make sure are correctly are the server name the path to the static files and proxy pass so right here we have our nginx called you know the name of our server which is Windows engine X I don't have any media but if you have any media you will want to update this path and the path to my static is I'm gonna cheat a little over here copy that and just copying and pasting that address makes it a little easier just to make sure that you don't have any spelling errors okay and the proxy pass will just be pointing to a local host 8080 and the reason for that is because I have a run server dot PI script here that this is going to be pulling in from the waitress module that I installed and we'll be importing the serve function and from my web project I'm going to be pointing to the Whiskey PI file and importing that application variable and to show you what I'm talking about so we have here the Whiskey dot pi file that's created when you start a Django project and automatically this application variable gets created okay so we have this set up the next thing that we need to do is go to where nginx is installed and create two directories sites enabled and sites available and in each of those directories we need to paste in that web project and gen-x come file so I'm going to navigate to the C Drive go to nginx and here I'm just going to type in sites available and sites enabled I'm go to my desktop and grab the Kampf I'll go back and just paste alright so you should have to come files located in those two directories the next step to make is to edit the nginx comp file and what you want to add is you want to add a line that says include and then the path to that it's not enabled web project nginx con file and then you also want to change one of the ports so I'm going to do this the easy way so I'm going to navigate to nginx golf and right click on this and I'm going to open this with code our visual studio code okay so we're I want to include that line include is right here and I just need the path I forgot was it it was sites enabled and you want to end the sign with a semicolon all right just to verify that this path is correct I'm going to copy it and I'm just gonna paste it right here on this address bar I'm gonna remove that semicolon hit enter and you can see it pointed me right to this file which is what we want I'm going to save that and one last thing that I wouldn't change is just by default the server is listening to port 80 put localhost and then serving this root directory HTML file and that HTML file is just like a simple nginx welcome text saying like hey things are working things are installed correctly for nginx but we don't want that what we want to reserve is that 80 that port 80 for our jingle web project so and changed that 80 to something that I know I won't use for me that's going to be 10 and I'm reserving that port 80 for my web project so that Jenko sorry nginx conserved my jingle project and its static files okay the last thing to do is to take this one server dot pi file I'm going to move it out here outside of that nginx waitress directory and the last thing to do is really just run this close that out actually I shouldn't have go back to my web project on my desktop Stephan's CMD again to open up a new terminal now we're going to type in Python run server PI okay you can see that we're running our server on port 8080 so I'm going to open up a new private window navigate to local localhost 8080 and you see that my simple app is being served now things look a little jarring that's because well things are misaligned they're not as I intended to display the content and that's because the CSS isn't being served what we really want is just to navigate to localhost that's it or look loaves 80 but first what we need to do is start up engine X so I'm going to open up a separate terminal after navigate to engine X directory type in CMD here and we have this file here that nginx that we want to execute the first thing that I want to do is type in engine X - t and that's just to do a quick sanity check you can see here that syntax is okay and the test is successful that's what we want last thing we need to do is just run nginx without any flags okay we can verify that nginx is running by navigating to the task manager under details you should see nginx running now I'm just going to open up a separate window go to localhost and you can see that now my web project is being served with it's with its CSS and so that's how to link your Django web project with nginx thanks for watching
Info
Channel: Johnnyboycurtis
Views: 9,038
Rating: undefined out of 5
Keywords: Python, Django, Windows, nginx, deploy, Windows Server, Google Cloud, Waitress, static files
Id: BBKq6H9Rm5g
Channel Id: undefined
Length: 12min 46sec (766 seconds)
Published: Tue May 26 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.