banner



How To Install Nginx In Amazon Linux

Since its introduction more than xv years ago, NGINX has gained steadily in popularity and is now the nearly pop web server in the globe, powering more than than 350 million websites. In this case nosotros think information technology's smart to follow the crowd and employ NGINX for all your web‑serving needs, and additionally to take reward of its capabilities as a reverse proxy, content cache, load balancer, API gateway, and more.

This web log post guides you in getting NGINX up and running on Ubuntu 20.04 on Amazon Web Services (AWS) in an piece of cake-to-employ setup that doesn't touch on the settings on your personal figurer. It covers both NGINX and NGINX Plus, the commercially supported version with additional enterprise‑grade features.

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

The tutorial includes instructions for these tasks:

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

Accessing a Concluding

For this tutorial, y'all need a terminal to connect to your Amazon Elastic Compute Deject (EC2) case. Macs take a built‑in terminal, but Windows users need to download PuTTY or an equivalent tool. If y'all prefer to use your own local terminal to set upwards NGINX or NGINX Plus and serve web content, feel free to skip to Setting upwardly AWS.

Accessing a Terminal on MacOS

On Macs, you lot can use the congenital‑in concluding tool to do everything in this tutorial.

  1. Click the magnifying glass icon at the right end of the top bar on the screen.

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

Accessing a Terminal on Windows

Windows doesn't come with a built‑in concluding, so you need to download one from the Internet. Along with AWS, we 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 selection, then open it. Y'all can't access the actual final until you lot end the steps in the Setting up AWS, however.

Setting Up AWS

In this tutorial we presume that you accept an Amazon Virtual Private Cloud (VPC) and tin simply employ the default VPC configuration that is created with well-nigh accounts. In this section, you set up your AWS deployment by creating an EC2 case and connecting to it.

Note: The following procedure and screenshots for creating an EC2 instance were verified at the time of writing, but are subject to change past AWS. Adapt the instructions as necessary.

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

  2. Click  Services in the Panel title bar, then  EC2 in the  Compute department.

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

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

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

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

  5. On the Step 2 page, select the t2.micro instance blazon, which equally of this writing is marked  Free tier eligible and selected by default. Click the Adjacent: Configure Instance Details button.

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

  6. On the Step 3 page, make sure the VPC you lot want to utilize is selected in the Network field, and that the Auto-assign Public IP field is fix either to the default Utilise Subnet setting (Enable) or to Enable. Leave the remainder of the settings at their defaults.

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

  7. Click vi. Configure Security Group at the acme of the page.

  8. On the Stride 6 page, perform the post-obit steps to allow incoming HTTP and HTTPS traffic (past default EC2 instances have only SSH traffic):

    • Click the  Add together Rule push button below the tabular array, and so select HTTP from the drop‑down menu in the Blazon column. For the purposes of this tutorial, we are allowing access from any IP address (the value in the Source column is Anywhere 0.0.0.0/0, ::/0). For production environments, we recommend you follow the warning on the page which mandates use of security groups to command access.

    • Repeat the previous stride for HTTPS.

    • Click the  Review and Launch push button at the lesser of the page.

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

  9. On the Pace 7 folio, 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‑down menu.

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

    • Type a proper noun in the Key pair name field, such as NGINX_key.

    • Click the  Download Key Pair push button.

    • Equally shown in the blithe screenshot below, a check box replaces the  Download Key Pair button. Click it to indicate that y'all 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 manager 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 button at the bottom.

  14. On the Instances folio that opens, the new example appears in the table. Give it a name:

    • Click the pencil icon in the Name cavalcade.

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

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

  15. Click the Connect button at the tiptop of the screen. A window like the following pops upward. Open the SSH client tab and follow the instructions to connect to the instance. If using Windows, substitute .ppk for .pem in the commands.

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

Installing NGINX Software

At present that your AWS environs is gear up, it'south time to install either NGINX Open Source or NGINX Plus, which yous tin can endeavour costless for thirty days. Both options piece of work in the context of this tutorial, but if you desire to further 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 Source available in their standard package repositories, simply it'south usually not the latest version. Nosotros recommend downloading NGINX Open Source directly from nginx.org. There are just a few extra steps for adding the NGINX repository to the Ubuntu packet 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 fundamental:

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

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

                  deb http://nginx.org/packages/ubuntu focal nginx deb-src http://nginx.org/packages/ubuntu focal nginx            

    Annotation: The focal keyword in each of these lines corresponds to Ubuntu 20.04. If you are using a different version of Ubuntu, substitute the start word of its release code proper noun (for example, bionic for Ubuntu 18.04).

  6. Update the NGINX software:

                  $                sudo apt-get update                          
  7. Install NGINX:

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

  9. Beginning NGINX:

                  $                sudo systemctl start nginx.service                          
  10. Check its status:

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

Installing NGINX Plus

  1. If y'all don't already take NGINX Plus, sign upwards for a 30‑24-hour interval free trial.

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

  3. When installation is complete and NGINX Plus is running, go on to Opening Your Web Page.

Opening Your Web Page

Now that you've started the NGINX software, take a look at the web page that NGINX and NGINX Plus serve past default before you configure them to evangelize your site's content. Follow these steps:

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

  2. Coil right in the table until you can run across the instance's public IP address in the Public IPv4 address column (in the screenshot, it's 3.22.51.xxx). Select the address and copy it 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 merely not yet configured.

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

Setting Upwardly Sample Files

With a working version of NGINX or NGINX Plus installed, it'south time to put it to good utilize! Begin by setting upwardly some files and directories.

  1. Change directory to your home directory if you lot 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 chosen index.html and a directory called application1.

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

  5. Alter dorsum to your home directory.

  6. Create a directory called data.

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

Serving Pages and Images

Our first use 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 information technology every bit the default configuration file.

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

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

    Directive documentation: location, root, server

  4. Change directory to ~/information/images.

  5. Detect an prototype that yous want to serve and copy information technology to the directory (~/data/images). As an instance, the post-obit command copies over the NGINX logo:

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

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

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

  8. Also access the application and observe what you get:

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

Setting Upwards a Proxy Server

Now that you lot take a working web server, it's time to learn how to configure information technology to route traffic. This capability enables you to pass traffic through to other servers and is a major pace towards setting upward load balancing. Follow these steps:

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

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

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

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

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

                  server {     heed 8080;     root /home/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 /dwelling/ubuntu/public_html;      location /application1 {         proxy_pass http://localhost:8080/sampleApp;     }      location /images {         root /dwelling/ubuntu/data;     } }            

    Directive documentation: location, proxy_pass, root, server

  7. Reload NGINX or NGINX Plus:

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

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

So that'southward information technology! You lot 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 additional use cases, run across our deployment guides.

Conclusion

In this tutorial, yous learned how to set NGINX or NGINX Plus to serve files and images over the Internet, and to human activity as a reverse proxy. If you desire to learn nigh NGINX in more depth, we offer the NGINX Core training course (instructor‑led or on‑demand) which covers the topics from this tutorial equally well as more essentials of web serving and application delivery, including load balancing, location‑based routing, and security. Also check out the documentation at nginx.org and the NGINX Plus Admin Guide – except as noted, the manufactures utilise to NGINX Open Source as well as NGINX Plus.

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

Posted by: heathyouds1976.blogspot.com

0 Response to "How To Install Nginx In Amazon Linux"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel