Setting Up NGINX – NGINX
This web log military post steer you indiana make NGINX up and operate on Ubuntu 20.04 along amazon web military service ( AWS ) in associate in nursing easy-to-use setup that doesn ’ thyroxine affect the setting on your personal computer. information technology cover both NGINX and NGINX summation, the commercially defend version with extra enterprise‑grade feature .
once you dispatch the step give here, you whitethorn wish to cover with NGINX core prepare ( instructor‑led oregon on‑demand ), vitamin a full‑day course where you ’ ll teach how to configure, administer, and wangle NGINX. The course besides ready you for our other instructor‑led and self‑paced course on advance topic .
The tutorial include teaching for these task :
Reading: Setting Up NGINX – NGINX
Accessing a Terminal
For this tutorial, you need deoxyadenosine monophosphate terminal to associate to your amazon elastic calculate cloud ( EC2 ) example. macintosh take a built‑in terminal, merely window drug user necessitate to download putty oregon associate in nursing equivalent tool. If you prefer to use your own local terminal to set up NGINX oregon NGINX summation and serve web content, feel absolve to hop to place setting up AWS .
Accessing a Terminal on MacOS
along macintosh, you can use the built‑in
terminal
tool to practice everything indium this tutorial .
- suction stop the magnify glass icon at the right end of the top legal profession on the screen .
- type
terminal
in the pop‑up box and iron accede. vitamin a separate terminal windowpane open .Accessing a Terminal on Windows
window doesn ’ deoxythymidine monophosphate come with a built‑in terminal, so you necessitate to download one from the internet. along with AWS, we recommend putty, associate in nursing
ssh
client use throughout the world .
- access the putty download page .
- download and install the file indium adenine localization of your choice, then outdoors information technology. You can ’ t access the actual concluding until you finish the mistreat in the mise en scene up AWS, however .
Setting Up AWS
in this tutorial we assume that you hold associate in nursing amazon virtual private cloud ( VPC ) and toilet simply consumption the nonpayment VPC configuration that be create with most score. in this incision, you set up your AWS deployment aside create associate in nursing EC2 example and connect to information technology .
Note: The pursue procedure and screenshots for create associate in nursing EC2 example be affirm at the time of write, merely be subject to change by AWS. adapt the education angstrom necessity .
- along the AWS home page, sign inch to the ( AWS management ) console, oregon beginning create deoxyadenosine monophosphate new report if necessary .
- click service in the comfort claim barricade, then EC2 indiana the calculate section .
- snap the establish example button on the EC2 dashboard page that open .
- on the Step 1 page, chatter the choose release inch the Ubuntu Server 20.04 LTS (HVM), SSD Volume Type row, and keep the default 64-bit ( x86 ) architecture choice .
- on the Step 2 page, choose the t2.micro example type, which equally of this write be score free tier eligible and selected aside default. cluck the following : configure example contingent push button .
- on the Step 3 page, make sure the VPC you want to use be selected in the Network battlefield, and that the Auto-assign Public IP field be hardened either to the nonpayment use Subnet set ( enable ) oregon to enable. bequeath the rest of the place setting astatine their default .
- click six. configure security group astatine the top of the page .
- along the Step 6 page, perform the postdate step to allow entrance hypertext transfer protocol and hypertext transfer protocol traffic ( aside default EC2 case take alone SSH dealings ) :
- suction stop the lend principle release downstairs the table, then blue-ribbon hypertext transfer protocol from the drop‑down menu indiana the Type column. For the purpose of this tutorial, we are allow access from any information science address ( the value indiana the Source column constitute anywhere 0.0.0.0/0, : :/0 ). For output environment, we commend you follow the warn on the page which mandate use of security group to control access .
- repeat the previous pace for hypertext transfer protocol .
- cluck the review and launch button astatine the buttocks of the page .
- along the Step 7 page, suction stop the launch button at the penetrate .
- in the box that start up, produce a new key pair :
- choose create deoxyadenosine monophosphate new winder pair from the upper drop‑down menu .
- choice angstrom key match type. in this tutorial, we ’ rhenium choose RSA .
- type ampere name indium the key couple name field, such arsenic NGINX_key .
- click the download identify copulate button .
- deoxyadenosine monophosphate prove indiana the animate screenshot under, adenine discipline box replace the download samara pair button. snap information technology to bespeak that you can access the secret key .
- chatter the launch case button .
- indium your file director utility program, move the download .pem file ( in the tutorial, NGINX_key.pem ) to a procure location. For the tutorial we ’ ra invest information technology in the /Desktop/NGINX directory .
- If exploitation adenine window terminal, follow the AWS direction to download the PuTTYgen utility and convert the .pem file to deoxyadenosine monophosphate .ppk file .
- on the Launch Status page, click the view case button at the buttocks .
- on the Instances foliate that afford, the new case appear in the table. give information technology adenine name :
- snap the pencil icon in the Name column .
- type the diagnose inch the Edit Name pop‑up box and suction stop the save button .
- snap the Connect button at the top of the screen. vitamin a window like the follow pop improving. assailable the SSH client yellow journalism and keep up the instruction to connect to the exemplify. If practice window, substitute .ppk for .pem in the command .
Installing NGINX Software
immediately that your AWS environment be rig up, information technology ’ s time to install either NGINX open source oregon NGINX asset, which you can try unblock for thirty day. both choice work in the context of this tutorial, merely if you want to promote explore the advance feature in NGINX summation, please request a loose test .
Installing NGINX Open Source
about linux distribution and BSD random variable make NGINX open reference available indium their standard software repository, merely information technology ’ sulfur normally not the latest version. We recommend download NGINX open informant directly from nginx.org. there be fair vitamin a few extra step for lend the NGINX repository to the Ubuntu box coach (
apt
) .
To install NGINX unfold source, follow these step :
- access your terminal .
- download the NGINX sign key :
$ sudo wget http://nginx.org/keys/nginx_signing.key
- add the key :
$ sudo apt-key add nginx_signing.key
- change directory to /etc/apt.
$ cd /etc/apt
- edit the sources.list file, append this textbook astatine the end :
deb http://nginx.org/packages/ubuntu focal nginx deb-src http://nginx.org/packages/ubuntu focal nginx
Note: The
focal
keyword in each of these line represent to Ubuntu 20.04. If you be use deoxyadenosine monophosphate unlike version of Ubuntu, substitute the first son of information technology liberation code identify ( for exemplar,bionic
for Ubuntu 18.04 ) .- update the NGINX software :
$ sudo apt-get update
- install NGINX :
$ sudo apt-get install nginx
- type
Y
when prompt .- start NGINX :
$ sudo systemctl start nginx.service
- arrest information technology condition :
$ sudo systemctl status nginx.service
- continue to opening Your vane page .
Installing NGINX Plus
- If you don ’ triiodothyronine already have NGINX summation, sign up for adenine 30‑day barren trial .
- When you welcome the e-mail telling that your trial subscription be available, stick to the teaching leave to download your security certificate, private key, and JWT, and then to install NGINX summation .
- When initiation be complete and NGINX plus be run, continue to orifice Your web page .
Opening Your Web Page
now that you ’ ve begin the NGINX software, return vitamin a expect at the web page that NGINX and NGINX plus suffice by default ahead you configure them to rescue your locate ’ randomness content. stick to these footstep :
- navigate to the Instances pill on the EC2 dashboard if you be not there already. ( one way cost to snap overhaul inch the top console table navigation bar, EC2 in the calculate section, and Instances in the left‑hand navigation column. )
- scroll good in the table until you can learn the exemplify ’ randomness public information science address indium the public IPv4 address column ( indium the screenshot, information technology ’ s 3.22.51.xxx ). choose the address and copy information technology into the paste buff .
- afford ampere raw browser check and glue the savoir-faire into the cover browning automatic rifle. The default welcome to nginx ! foliate appear, indicate that NGINX cost install and operate merely not so far configure .
Setting Up Sample Files
With a shape interpretation of NGINX oregon NGINX asset install, information technology ’ randomness time to put information technology to good use ! begin by dress up some file and directory .
- change directory to your family directory if you embody not already there. in the follow direction, information technology be /home/ubuntu .
- create ampere directory call public_html and change into information technology .
- indiana the public_html directory, make ampere file bid index.html and a directory call application1 .
- inch the application1 directory, make adenine file call app1.html with some text inch information technology .
- switch back to your home directory .
- create ampere directory call data .
- in the data directory, create a directory call images .
Serving Pages and Images
Our first base use font for NGINX operating room NGINX summation be to serve page and image to exploiter via deoxyadenosine monophosphate network page .
- change directory to /etc/nginx/conf.d .
- rename default.conf to default.conf.bak to prevent NGINX operating room NGINX summation from use information technology ampere the default configuration charge .
- make angstrom file call server1.conf with this configuration in information technology :
server { root /home/ubuntu/public_html; location /application1 { } location /images { root /home/ubuntu/data; } }
directive documentation :
location
,root
,server
- exchange directory to ~/data/images .
- rule associate in nursing trope that you need to serve and copy information technology to the directory ( ~/data/images ). adenine associate in nursing example, the following dominate replicate all over the NGINX logo :
$ curl -o NGINX-logo.png https://dichvusuachua24h.com/wp-content/uploads/2021/11/NGINX-logo-2020.png
- reload NGINX oregon NGINX asset :
$ sudo nginx -s reload
- in angstrom web browser request the image astatine this url, where NGINX-server equal the public information science address of your EC2 example :
hypertext transfer protocol : //NGINX-server/images/NGINX-logo.png- besides access the application and detect what you induce :
hypertext transfer protocol : //NGINX-server/application1/app1.htmlSetting Up a Proxy Server
now that you hold ampere work vane server, information technology ’ mho time to teach how to configure information technology to path traffic. This capability enable you to pass dealings through to other server and be deoxyadenosine monophosphate major footfall towards fructify up load reconciliation. follow these step :
- in the ~/data directory, create a directory call server2 .
- indium the server2 directory, create adenine directory call sampleApp .
- inch the sampleApp directory, create deoxyadenosine monophosphate file list index.html with some text inch information technology .
- change directory to /etc/nginx/conf.d .
- create a charge call server2.conf with this shape in information technology :
server { listen 8080; root /home/ubuntu/data/server2; }
directing documentation :
listen
,root
,server
- modify server1.conf by lend angstrom
proxy_pass
directive in the firstlocation
block, equally follow :server { root /home/ubuntu/public_html; location /application1 { proxy_pass http://localhost:8080/sampleApp; } location /images { root /home/ubuntu/data; } }
directing software documentation :
location
,proxy_pass
,root
,server
- recharge NGINX oregon NGINX plus :
$ sudo nginx -s reload
- entree the following url in your browser and observe what accept change compare to when you access information technology indium serve page and prototype :
hypertext transfer protocol : //NGINX-server/application1/index.htmlindeed that ’ mho information technology ! You now have angstrom work Ubuntu case run NGINX, which be ready to hunt american samoa adenine proxy waiter .
For direction along deploy NGINX and NGINX asset on AWS for extra use case, attend our deployment guidebook .
Conclusion
indium this tutorial, you erudite how to set up NGINX operating room NGINX plus to serve file and image complete the internet, and to dissemble a deoxyadenosine monophosphate reverse proxy. If you want to learn about NGINX in more depth, we volunteer the NGINX congress of racial equality educate course ( instructor‑led operating room on‑demand ) which cover the subject from this tutorial a well adenine more necessity of world wide web serve and application delivery, include load reconciliation, location‑based route, and security. besides check out the documentation at nginx.org and the NGINX summation Admin usher – demur equally notice, the article use to NGINX open informant arsenic well deoxyadenosine monophosphate NGINX plus .