1 00:00:07,220 --> 00:00:12,740 In this final video of the feature section we'll see how to configure Geo IP look ups directly from 2 00:00:12,740 --> 00:00:15,730 Engine X first off to enable this module. 3 00:00:15,740 --> 00:00:22,520 You will have to tell engine extra included by specifying the flag with HTP Geo IP module as we did 4 00:00:22,520 --> 00:00:24,440 with them before module. 5 00:00:24,440 --> 00:00:27,900 Now should you run your configuration and get the following error. 6 00:00:27,920 --> 00:00:35,570 You can install the missing dependency by running app get install the geo IP dash dev or the equivalent 7 00:00:35,570 --> 00:00:38,550 of whichever package manager you're using on your server. 8 00:00:38,990 --> 00:00:44,480 Once that's done we can configure the engine explode with the geo IP flag run that. 9 00:00:49,340 --> 00:00:50,580 And install. 10 00:00:52,230 --> 00:00:53,120 Running engine x. 11 00:00:53,130 --> 00:00:59,790 Capital V will confirm that our engineers install now includes the geo IP module so we can reload the 12 00:00:59,790 --> 00:01:07,080 configuration and start configuring the GOP module to use the GOP module will first need to download 13 00:01:07,110 --> 00:01:15,570 the max mind Geo IP database and for that I'll create a new directories on the server slash ebc slash 14 00:01:15,600 --> 00:01:20,300 engine X slash Geo IP and I'll change into that directory. 15 00:01:21,140 --> 00:01:25,850 Over to the browser and will navigated dev dot Max mind dot com. 16 00:01:27,540 --> 00:01:29,280 And a bit further down the page. 17 00:01:29,290 --> 00:01:30,830 Select Geo light. 18 00:01:30,850 --> 00:01:33,150 Legacy free download. 19 00:01:33,580 --> 00:01:38,760 I'm using the legacy packages as they are arguably still the preferred choice for in gen-x and matched 20 00:01:38,770 --> 00:01:41,360 the documentation of the geo IP module. 21 00:01:41,640 --> 00:01:47,800 The two databases I'm going to download is the geo light country and the geo light city so I'll copy 22 00:01:47,800 --> 00:01:49,090 that download link. 23 00:01:51,410 --> 00:01:54,920 Download the Jesus file to the geo IP directly. 24 00:01:55,890 --> 00:01:57,570 Unzip it using guns up. 25 00:01:59,380 --> 00:02:02,270 Then do the same for the city database. 26 00:02:09,130 --> 00:02:12,720 There we have our two Geo IP database files. 27 00:02:12,790 --> 00:02:17,860 Now I'll switch over to the engine X configuration file and just remove that red limiting rule from 28 00:02:17,860 --> 00:02:23,890 a previous video then to configure Geo IP we're going to tell engine X where to find those databased 29 00:02:23,890 --> 00:02:25,030 files. 30 00:02:25,060 --> 00:02:29,430 This is just done in its tgb context so it's available everywhere. 31 00:02:29,440 --> 00:02:36,730 First will say gee do I be underscore country and say that you slash iti slash engineer X slash Geo 32 00:02:36,740 --> 00:02:39,720 I'd be slashed to you be done to a T. 33 00:02:40,000 --> 00:02:46,110 Which is that first database file we downloaded and then the same for geo IP underscore city. 34 00:02:47,800 --> 00:02:48,420 See. 35 00:02:48,440 --> 00:02:52,730 Slash engineer slash Geo I be slessor Geo light city. 36 00:02:52,750 --> 00:02:54,490 Don't be a T. 37 00:02:54,660 --> 00:02:56,230 Switch over to the terminal. 38 00:02:56,270 --> 00:03:00,400 Check that configuration and something isn't right. 39 00:03:02,000 --> 00:03:04,820 Just a typo in that first file name. 40 00:03:05,350 --> 00:03:06,370 Try again. 41 00:03:06,640 --> 00:03:10,420 And now everything looks fine so I'll reload the configuration. 42 00:03:11,060 --> 00:03:16,760 Right to use the geo IP module will have to specify what information we want and to get a list of all 43 00:03:16,760 --> 00:03:17,530 the variables. 44 00:03:17,540 --> 00:03:18,880 The module makes available. 45 00:03:18,890 --> 00:03:21,870 We'll head over to the documentation page first. 46 00:03:21,980 --> 00:03:24,540 Take a look at Geo IP country. 47 00:03:24,560 --> 00:03:31,040 This provides us with three variables and to demonstrate I am going to use the geo IP country name variable 48 00:03:31,040 --> 00:03:32,030 first. 49 00:03:32,520 --> 00:03:39,060 Back to the configuration file and I'll create a new location block or slash Geo underscore country 50 00:03:39,840 --> 00:03:47,670 and to keep this simple we'll just return a string with response code 200 and we'll say visiting from 51 00:03:48,000 --> 00:03:52,380 Geo IP country name save their own reload. 52 00:03:52,910 --> 00:03:56,450 Head over to the browser and go to that your URL. 53 00:03:57,280 --> 00:03:59,040 Do you underscore country. 54 00:04:00,810 --> 00:04:07,710 And we get visiting from South Africa as that we are recording this video and making the request from. 55 00:04:07,740 --> 00:04:13,200 If however we head over to the terminal and do a call request from this digital ocean server. 56 00:04:13,800 --> 00:04:18,970 We get visiting from United Kingdom as this is a London based virtual machine. 57 00:04:19,970 --> 00:04:25,410 Okay next I'll try the city database and back on that documentation page we can see just a bit further 58 00:04:25,410 --> 00:04:25,830 down. 59 00:04:25,830 --> 00:04:27,640 It's quite a few variables. 60 00:04:27,750 --> 00:04:33,180 In fact using the city database we can get everything from latitude and longitude oesterle code and 61 00:04:33,180 --> 00:04:36,270 city name which will try as well. 62 00:04:36,270 --> 00:04:41,530 So change that your URL to geo underscore city change the variable to Geo. 63 00:04:41,530 --> 00:04:44,550 I be city and reload. 64 00:04:45,250 --> 00:04:51,520 Now unfortunately my city is a bit more remote and isn't returned with this version of the city database 65 00:04:51,820 --> 00:04:53,430 so I'll skip the browser. 66 00:04:53,620 --> 00:05:00,080 But if we do that call request from the digital ocean server again we get visiting from London. 67 00:05:00,920 --> 00:05:06,110 In a real world scenario you could of course use these variables in rewrites to serve location specific 68 00:05:06,110 --> 00:05:10,960 content pass them to a back end or even apply restrictions based on location. 69 00:05:10,970 --> 00:05:15,320 The possibilities are quite endless and overall this is a very useful module to know.