0% found this document useful (0 votes)
28 views2 pages

Lab 1.1 Install Open Source Nginx On Centos

This document provides instructions for installing the open source NGINX web server on CentOS 7 and configuring it to use dynamic JavaScript modules. It involves: 1. Creating a yum repository file to install NGINX from its mainline repository 2. Installing NGINX using yum 3. Creating a simple JavaScript file and configuring NGINX to use it 4. Installing the nginx-module-njs package to enable JavaScript support 5. Reloading NGINX to apply the configuration changes

Uploaded by

coba yud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Lab 1.1 Install Open Source Nginx On Centos

This document provides instructions for installing the open source NGINX web server on CentOS 7 and configuring it to use dynamic JavaScript modules. It involves: 1. Creating a yum repository file to install NGINX from its mainline repository 2. Installing NGINX using yum 3. Creating a simple JavaScript file and configuring NGINX to use it 4. Installing the nginx-module-njs package to enable JavaScript support 5. Reloading NGINX to apply the configuration changes

Uploaded by

coba yud
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lab 1.

1 Install open source NGINX on CentOS

1. Create the nginx.repo file in the yum repository

vim /etc/yum.repos.d/nginx.repo

2. Copy the following into nginx.repo


3. [nginx]
4. name=nginx repo
5. baseurl=https://nginx.org/packages/mainline/centos/7/$basearch/
6. gpgcheck=0
7. enabled=1
8. Save and exit nginx.repo
9. Update package components and install nginx

yum update && yum install nginx -y

10. Click "y" when prompted to download NGINX.


11. Start the nginx process

nginx

12. Verify that NGINX is running

curl localhost

If NGINX is correctly installed you'll see a "Welcome to NGINX" page.

Lab 1.2 Download and install a dynamic module

1. Create a simple JavaScript.

vim /etc/nginx/moduletest.js

2. Paste the javascript below into the file.


3. function moduleTest(res) {
4. res.return(200, "The njs module was loaded\n");
5. }
6. Save and exit moduletest.js
7. Open /etc/nginx/nginx.conf

vim /etc/nginx/nginx.conf

8. In the HTTP context (between the brackets following http) enter the following:

js_include moduletest.js;

9. Beneath the line you just entered, paste the following nginx configuration:
10. server {
11. listen 80;
12. location / {
13. js_content moduleTest;
14. }
15. }
16. Save and exit nginx.conf
17. Rename nginx default configuraiton.

mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak

18. Reload NGINX

nginx -s reload

You should get an error - unknown directive. This indicates that the njs module
hasn't been installed.

19. Use yum to download and install the njs module

yum install nginx-module-njs -y

20. When the install is complete, open /etc/nginx/nginx.conf

vim /etc/nginx/nginx.conf

21. Near the top of the file nginx.conf, add the following lines to enable the njs module in
both the http and stream modules:
22. load_module modules/ngx_http_js_module.so;
23. load_module modules/ngx_stream_js_module.so;
24. Save and exit nginx.conf
25. Reload nginx to affect changes

nginx -s reload

26. Curl localhost.

curl localhost

You should see the output of our javascript, "the njs module was loaded"

You might also like