banner



How To Install Nginx On Amazon Linux 2

Since its introduction more than fifteen years ago, NGINX has gained steadily in popularity and is at present the near popular web server in the globe, powering more than 350 million websites. In this case we recollect it's smart to follow the crowd and employ NGINX for all your web‑serving needs, and additionally to take advantage of its capabilities as a reverse proxy, content cache, load balancer, API gateway, and more.

This blog post guides you in getting NGINX up and running on Ubuntu xx.04 on Amazon Web Services (AWS) in an easy-to-use setup that doesn't affect the settings on your personal computer. Information technology covers both NGINX and NGINX Plus, the commercially supported version with additional enterprise‑grade features.

Once you complete the steps given here, yous may want to continue with NGINX Core training (teacher‑led or on‑demand), a total‑day course where you lot'll learn how to configure, administer, and manage NGINX. The course besides readies y'all for our other instructor‑led and cocky‑paced courses on advanced topics.

The tutorial includes instructions for these tasks:

  • Setting Upwards AWS
  • Installing NGINX Software
  • Opening Your Spider web Page
  • Setting Upwards Sample Files
  • Serving Pages and Images
  • Setting Up a Proxy Server

Accessing a Concluding

For this tutorial, you need a final to connect to your Amazon Elastic Compute Cloud (EC2) instance. Macs have a built‑in concluding, but Windows users need to download PuTTY or an equivalent tool. If you prefer to employ your own local terminal to set NGINX or NGINX Plus and serve web content, experience free to skip to Setting upwardly AWS.

Accessing a Terminal on MacOS

On Macs, you can use the built‑in concluding tool to exercise everything in this tutorial.

  1. Click the magnifying drinking glass icon at the right cease of the pinnacle bar on the screen.

  2. Type final in the pop‑upward box and press Enter. A separate terminal window opens.

Accessing a Terminal on Windows

Windows doesn't come with a congenital‑in terminal, then you need to download one from the Internet. Along with AWS, nosotros recommend PuTTY, an ssh client used throughout the world.

  1. Access the PUTTY download page.

  2. Download and install the file in a location of your choice, and so open information technology. You tin can't admission the actual final until y'all finish the steps in the Setting up AWS, nevertheless.

Setting Upwardly AWS

In this tutorial we assume that you have an Amazon Virtual Private Cloud (VPC) and can simply apply the default VPC configuration that is created with almost accounts. In this section, you fix your AWS deployment by creating an EC2 instance and connecting to it.

Note: The post-obit procedure and screenshots for creating an EC2 instance were verified at the time of writing, but are subject to alter by AWS. Accommodate the instructions as necessary.

  1. On the AWS dwelling page, sign in to the (AWS Management) Console, or first create a new account if necessary.

  2. Click  Services in the Console title bar, and then  EC2 in the  Compute section.

    Screenshot showing selection of 'EC2' on AWS 'Services' page

  3. Click the  Launch Instance push on the EC2 Dashboard page that opens.

  4. On the Step 1 page, click the  Select push button in the Ubuntu Server 20.04 LTS (HVM), SSD Volume Type row, and keep the default 64-bit (x86) architecture option.

    Screenshot of 'Step 1' page in Amazon EC2 instance-creation wizard

  5. On the Step two page, select the t2.micro example type, which equally of this writing is marked  Complimentary tier eligible and selected by default. Click the Next: Configure Instance Details button.

    Screenshot of 'Step 2' page in Amazon EC2 instance-creation wizard

  6. On the Pace 3 folio, make sure the VPC yous desire to use is selected in the Network field, and that the Auto-assign Public IP field is set either to the default Utilize Subnet setting (Enable) or to Enable. Leave the residue of the settings at their defaults.

    Screenshot of 'Step 3' page in Amazon EC2 instance-creation wizard

  7. Click 6. Configure Security Group at the height of the page.

  8. On the Footstep 6 page, perform the following steps to allow incoming HTTP and HTTPS traffic (by default EC2 instances have only SSH traffic):

    • Click the  Add Rule button below the table, then select HTTP from the driblet‑downward menu in the Type column. For the purposes of this tutorial, we are allowing access from any IP accost (the value in the Source column is Anywhere 0.0.0.0/0, ::/0). For product environments, we recommend y'all follow the alarm on the page which mandates utilise of security groups to control admission.

    • Repeat the previous stride for HTTPS.

    • Click the  Review and Launch button at the bottom of the page.

    Screenshot of 'Step 6' page in Amazon EC2 instance-creation wizard

  9. On the Step vii page, click the  Launch push button at the bottom.

  10. In the box that pops up, create a new key pair:

    • Select Create a new key pair from the upper drop‑downward menu.

    • Select a central pair type. In this tutorial, we're selecting RSA.

    • Blazon a proper name in the Central pair name field, such as NGINX_key.

    • Click the  Download Key Pair push button.

    • Equally shown in the animated screenshot below, a check box replaces the  Download Primal Pair button. Click it to indicate that you tin can admission the private key.

    • Click the  Launch Instances button.

    Screenshot of Amazon EC2 'Select and existing key pair or create a new key pair' pop-up window

  11. In your file director utility, move the downloaded .pem file (in the tutorial, NGINX_key.pem) to a secure location. For the tutorial we're placing it in the /Desktop/NGINX directory.

  12. If using a Windows terminal, follow the AWS instructions to download the PuTTYgen utility and convert the .pem file to a .ppk file.

  13. On the Launch Status page, click the  View Instances push at the bottom.

  14. On the Instances page that opens, the new instance appears in the table. Requite information technology a name:

    • Click the pencil icon in the Name column.

    • Type the proper noun in the Edit Name pop‑up box and click the  Relieve button.

    Screenshot of Amazon EC2 'Instances' page showing editing of instance name

  15. Click the Connect push at the top of the screen. A window similar the following pops upwardly. Open the SSH client tab and follow the instructions to connect to the example. If using Windows, substitute .ppk for .pem in the commands.

    Screenshot of Amazon EC2 'Connect to instance' pop-up window

Installing NGINX Software

Now that your AWS surroundings is set upwards, it's time to install either NGINX Open up Source or NGINX Plus, which you can try free for xxx days. Both options piece of work in the context of this tutorial, just if you want to farther explore the advanced features in NGINX Plus, delight request a free trial.

Installing NGINX Open Source

Most Linux distributions and BSD variants make NGINX Open up Source available in their standard parcel repositories, simply information technology'southward usually non the latest version. Nosotros recommend downloading NGINX Open Source directly from nginx.org. At that place are just a few extra steps for calculation the NGINX repository to the Ubuntu package manager (apt).

To install NGINX Open Source, follow these steps:

  1. Admission your terminal.

  2. Download the NGINX signing key:

                  $                sudo wget http://nginx.org/keys/nginx_signing.fundamental                          
  3. Add the key:

                  $                sudo apt-key add nginx_signing.key                          
  4. Change directory to /etc/apt.

                  $                cd /etc/apt                          
  5. Edit the sources.listing file, appending this text at the finish:

                  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 lines corresponds to Ubuntu 20.04. If you are using a different version of Ubuntu, substitute the first word of its release code name (for case, bionic for Ubuntu xviii.04).

  6. Update the NGINX software:

                  $                sudo apt-get update                          
  7. Install NGINX:

                  $                sudo apt-get install nginx                          
  8. Blazon Y when prompted.

  9. Outset NGINX:

                  $                sudo systemctl start nginx.service                          
  10. Bank check its status:

                  $                sudo systemctl status nginx.service                          
  11. Continue to Opening Your Web Page.

Installing NGINX Plus

  1. If you lot don't already accept NGINX Plus, sign up for a 30‑24-hour interval complimentary trial.

  2. When yous receive the email notification that your trial subscription is available, follow the instructions provided to download your security certificate, private primal, and JWT, and and then to install NGINX Plus.

  3. When installation is complete and NGINX Plus is running, continue to Opening Your Spider web Page.

Opening Your Spider web Page

At present that yous've started the NGINX software, accept a look at the web page that NGINX and NGINX Plus serve by default before you configure them to deliver your site's content. Follow these steps:

  1. Navigate to the Instances tab on the EC2 Dashboard if you are not there already. (1 way is to click  Services in the top Console navigation bar,  EC2 in the  Compute section, and Instances in the left‑hand navigation column.)

  2. Coil right in the table until you lot can see the instance's public IP address in the Public IPv4 address cavalcade (in the screenshot, it'south iii.22.51.xxx). Select the address and re-create information technology into the paste buffer.

    Screenshot of Amazon EC2 'Instances' page showing 'Public IPv4 address' field for an instance

  3. Open a new browser tab and paste the accost into the address bar. The default Welcome to nginx! page appears, indicating that NGINX is installed and running simply non yet configured.

    The welcome page confirms that your NGINX reverse proxy and web server is up and running

Setting Up Sample Files

With a working version of NGINX or NGINX Plus installed, it's time to put it to adept use! Brainstorm by setting upwards some files and directories.

  1. Change directory to your dwelling directory if you are not already there. In the following instructions, it is /home/ubuntu.

  2. Create a directory called public_html and change into it.

  3. In the public_html directory, create a file called alphabetize.html and a directory chosen application1.

  4. In the application1 directory, create a file called app1.html with some text in information technology.

  5. Change dorsum to your home directory.

  6. Create a directory chosen data.

  7. In the data directory, create a directory called images.

Serving Pages and Images

Our starting time utilise case for NGINX or NGINX Plus is to serve pages and images to users via a web page.

  1. Change directory to /etc/nginx/conf.d.

  2. Rename default.conf to default.conf.bak to foreclose NGINX or NGINX Plus from using it equally the default configuration file.

  3. Create a file chosen server1.conf with this configuration in it:

                  server {     root /home/ubuntu/public_html;      location /application1 {  }      location /images {		         root /domicile/ubuntu/data;	     } }            

    Directive documentation: location, root, server

  4. Modify directory to ~/data/images.

  5. Detect an image that you want to serve and re-create it to the directory (~/data/images). Every bit an case, the following command copies over the NGINX logo:

                  $                curl -o NGINX-logo.png https://www.nginx.com/wp-content/uploads/2021/eleven/NGINX-logo-2020.png                          
  6. Reload NGINX or NGINX Plus:

                  $                sudo nginx -s reload                          
  7. In a web browser asking the image at this URL, where NGINX-server is the public IP address of your EC2 case:

    https://NGINX-server/images/NGINX-logo.png

  8. Besides access the application and observe what you go:

    https://NGINX-server/application1/app1.html

Setting Upwardly a Proxy Server

At present that you have a working web server, information technology's time to learn how to configure it to route traffic. This capability enables you to laissez passer traffic through to other servers and is a major footstep towards setting upward load balancing. Follow these steps:

  1. In the ~/data directory, create a directory called server2.

  2. In the server2 directory, create a directory called sampleApp.

  3. In the sampleApp directory, create a file named index.html with some text in it.

  4. Modify directory to /etc/nginx/conf.d.

  5. Create a file chosen server2.conf with this configuration in it:

                  server {     heed 8080;     root /abode/ubuntu/data/server2; }            

    Directive documentation: listen, root, server

  6. Modify server1.conf by adding a proxy_pass directive in the first location block, as follows:

                  server {     root /home/ubuntu/public_html;      location /application1 {         proxy_pass http://localhost:8080/sampleApp;     }      location /images {         root /home/ubuntu/data;     } }            

    Directive documentation: location, proxy_pass, root, server

  7. Reload NGINX or NGINX Plus:

                  $                sudo nginx -s reload                          
  8. Admission the following URL in your browser and find what has changed compared to when you lot accessed it in Serving Pages and Images:

    https://NGINX-server/application1/index.html

So that's it! You at present have a working Ubuntu instance running NGINX, which is ready to run as a proxy server.

For instructions on deploying NGINX and NGINX Plus on AWS for boosted use cases, run into our deployment guides.

Conclusion

In this tutorial, you learned how to gear up NGINX or NGINX Plus to serve files and images over the Internet, and to deed equally a reverse proxy. If you want to learn most NGINX in more depth, nosotros offer the NGINX Core preparation course (instructor‑led or on‑demand) which covers the topics from this tutorial besides equally more than essentials of web serving and awarding delivery, including load balancing, location‑based routing, and security. Also bank check out the documentation at nginx.org and the NGINX Plus Admin Guide – except every bit noted, the manufactures apply to NGINX Open up Source as well as NGINX Plus.

Source: https://www.nginx.com/blog/setting-up-nginx/

Posted by: choiwhyall.blogspot.com

0 Response to "How To Install Nginx On Amazon Linux 2"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel