Welcome to example-one.com

How to install NGINX on AWS EC2 Linux 2 [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.

  • Via EPEL as the blog entry
  • Amazon’s own (?) version as this answer
  • The 2016 NGINX official tutorial

On my development environment (Centos VM) I used sudo yum install nginx . Having tried the EPEL route I don’t get the same set up, in particular sites enabled/available is not created as part of the setup. I want to use nginxconfig.io which requires those. Which version of NGINX should i use for that?

2 Answers 2

Alternative way to install that could be easier (has a fairly recent version of Nginx):

$ sudo amazon-linux-extras list | grep nginx 38 nginx1=latest disabled [ =stable ] $ sudo amazon-linux-extras enable nginx1 38 nginx1=latest enabled [ =stable ] Now you can install: $ sudo yum clean metadata $ sudo yum -y install nginx $ nginx -v nginx version: nginx/1.16.1 

I’d personally use Amazon’s own repo.

The version provided by the Amazon repo is relatively old ( 1.12.2 at the time of writing). To see what versions the Amazon repo has access to run

amazon-linux-extras list | grep nginx 

If you’d like a later version, consider EPEL.

In regards to the config, your best bet is to explicitly supply the configuration you require to the server.

Using the off-the-peg ones are fine to get you up and running. However you run the risk of things changing when Nginx updates. Explicitly supplying your own configuration gives you greater control over what is running.

Probably the simplest approach would be to upload the configuration generated by nginxconfig.io to S3.

Then add a script via user data when creating the EC2 instance to download your configuration.

#!/bin/bash # Install Nginx amazon-linux-extras install nginx1.12 # Back up existing config mv /etc/nginx /etc/nginx-backup # Download the configuration from S3 aws s3 cp s3:///nginxconfig.io-example.com.zip /tmp # Install new configuration unzip /tmp/nginxconfig.io-example.com.zip -d /etc/nginx 

The configuration supplied by nginxconfig.io sets up all the sites enabled/available for you.

Источник

Installing NGINX Plus AMIs on Amazon EC2

Install NGINX Plus on Amazon Web Services (AWS), to provide sophisticated Layer 7 load balancing for your apps running on Amazon Linux, RHEL, and Ubuntu.

Читайте также:  Del file in linux

NGINX, Inc. participates in the Amazon Web Services (AWS) Partner Network as a Standard Technology Partner. We offer Amazon Machine Images (AMIs) for use in the Amazon Elastic Compute Cloud (EC2), available at the AWS Marketplace for several operating systems, including Amazon Linux, Red Hat Enterprise Linux, and Ubuntu.

The AMIs contain the following components:

  • Latest version of NGINX Plus, optimized for use on Amazon EC2
  • Pre-packaged software for building highly available (HA) NGINX Plus configurations

Installing the NGINX Plus AMI

To quickly set up an NGINX Plus environment on AWS:

  1. Follow the instructions in Getting Started with Amazon EC2 Linux Instances to sign up on AWS and get more information about EC2 itself.
  2. Proceed to the product page for the appropriate AMI at the AWS Marketplace, and launch the AMI.
    • NGINX Plus – Amazon Linux AMI HVM
    • NGINX Plus – Red Hat Enterprise Linux 7 AMI HVM
    • NGINX Plus – Red Hat Enterprise Linux 6 AMI HVM
    • NGINX Plus – Ubuntu AMI HVM

Click the Continue to Subscribe button to proceed to the Launch on EC2 page.

What If I Need Help?

If you encounter any problems with NGINX Plus configuration, documentation is available at nginx.org and in the NGINX Plus Admin Guide.

Customers who purchase an NGINX Plus AMI at the AWS Marketplace are eligible for the AWS support provided by the NGINX, Inc. engineering team. To activate support, submit the AMI Support Activation form (you need your AWS account number). When you request support, we’ll ask you to provide the AWS account number that you registered, along with the IDs of your EC2 instances in some cases.

Источник

How to install Nginx on Amazon Linux 2

Installing Nginx from the Amazon Linux repo will provide you with an exceedingly old Nginx version. Therefore, I will show you how to install it through the EPEL repo which is my preferred choice when it comes to an RHEL Linux-based distro.

Prerequisites

Enable and Install EPEL repo on AWS EC2 Amazon Linux 2 instance

Step 1. First, check if the EPEL repository is enabled.

sudo amazon-linux-extras list | grep epel 

If you get the following output:

24 epel available [ =7.11 =stable ] 

Then, it means that you should enable it before installing Nginx.

Step 2. Enable the EPEL repo on Amazon Linux 2 instance.

sudo amazon-linux-extras enable epel 

Step 3. Now, you should be able to install the EPEL repo.

sudo yum install epel-release 

Install Nginx on AWS EC2 Amazon Linux 2 instance

Step 1. Once the EPEL repo is installed you can install the Nginx latest version as well.

Step 2. Verify installation.

Conclusion

This tutorial is aimed to provide you with a quick and safe path of installing Nginx on Amazon Linux 2 instance. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.

Источник

How To Install and Configure Nginx on Amazon ec2 RHEL and Ubuntu Instances

Install and Configure Nginx on Amazon ec2 RHEL and Ubuntu Instances

Nginx is a web server like apache. Not only as a web server, but it can also act as a load balancer, reverse proxy, etc. Performance-wise, Nginx is considered to be better than apache. Processing request in Nginx is even based as opposed to the spanning new thread model in apache.

In this tutorial, I will explain how to install and configure Nginx on ec2 RHEL and ubuntu instances.

The process for installing & configuring Nginx on RHEL , Centos and Amazon Linux is the same.

Instance Setup

  1. Launch an RHEL/Centos/Ubuntu instance using the management console. While launching the instance , configure the security group to allow traffic from HTTP 80 port & HTTPS 443.
  2. Connect the instance using putty.
  3. You can also setup password authentication to the ec2 instance

Nginx Setup on RHEL/Centos/Ubuntu

In this guide, we will look in the following.

Install Nginx on RHEL & Centos

Step 1: In RHEL you cannot download and install Nginx directly. You have to setup the epel ( extra packages for enterprise Linux) repo to install Nginx. Install EPEL package repository.

sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

For Centos, execute the following.

sudo yum install -y epel-release

Step 2: Update the package list.

Step 3: Install Nginx

Install Nginx on Ubuntu

Execute the following steps to install Nginx on Ubuntu servers.

sudo apt update sudo apt install nginx -y

Start and Enable Nginx

Following steps are common for RHEL and Ubuntu systems.

Step 1: Check the version to make sure Nginx is installed.

Step 2: Start and enable Nginx.

sudo systemctl start nginx sudo systemctl enable nginx

Step 3: Check the status of Nginx to make sure it is running as expected.

sudo systemctl status nginx

Step 4: Visit the nginx page using the Server IP. You should be seeing

nginx home page

Setting up Multiple Domains Using Nginx Server Blocks

When you have one or more websites to be hosted on the same Nginx server, you need to use the Virtual Hosts configuration.

In this section I will show you how to create a virtual host configuration for a website.

Step 1: Create the website folder and a public folder to put the static assets inside /var/www

Here am going to give the name as example-one.com. Name the folder with your website name. It will be easy to identify if you have many websites running on the same server.

sudo mkdir /var/www/example-one.com/public_html

Step 2: Create a test index.html file if you dont have your own index file.

sudo vi /var/www/example-one.com/public_html/index.html

Copy the following contents and save the file.

      

Welcome To example-one.com home page!

Step 3: Change the ownership of the root document to the user which is managing the worker process.

For RHEL/Centos the user is nginx,

sudo chown -R nginx: /var/www/example-one.com

In most of the RHEL/Centos distributions, SElinux will be set to in enforcing mode. Execute the following commands for SELinux to allow accessing the nginx website files.

sudo setsebool -P httpd_can_network_connect on chcon -Rt httpd_sys_content_t /var/www/

For Ubuntu the user is www-data,

sudo chown -R www-data: /var/www/example-one.com

Step 4: Create a Nginx configuration file with the websites name

Create the config gile under /etc/nginx/conf.d/ folder.

sudo vi /etc/nginx/conf.d/example-one.com.conf

Create the config file under /etc/nginx/sites-available/ folder.

sudo vi /etc/nginx/sites-available/example-one.com.conf

Copy the following server block configuration the conf file and save it.

Note: Replace example-one with your domain name.

Only on Ubuntu server, execute the following command to create a symbolic link to sites-enabled folder.

sudo ln -s /etc/nginx/sites-available/example-one.com.conf /etc/nginx/sites-enabled/example-one.com.conf

Step 5: Validate the server block configuration using the following command.

If should get the following success message.

$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

Step 6: Restart the nginx server.

sudo systemctl restart nginx

If you use the public DNS of the ec2 instance , the server will throw the following error when you restart the Nginx server.

nginx: [emerg] could not build the server_names_hash, you should increase server_names_hash_bucket_size: 64

Since the DNS name is pretty long , you have to add the server name bucket size to 128 to the example-one.conf file.

server_names_hash_bucket_size 128;

Now you will be able to access the website using your domain name. If you have used the test domain names, add it to your systems /etc/hosts file and try accessing the website.

To add more domains to the nginx server, follow the same steps with a different domain name and config names as explained.

Nginx SSL Setup

Optionally you can setup SSL for your Nginx websites. You can use the free SSL certificates from Letsencrpt for your SSL need.

I have written a tutorial for setting up SSL using Letsencryp. Read the tutorial here -> Nginx Letsencrypt Setup Guide Using Certbot

Load balancing using Nginx

You can use Nginx as a load balancer to balance the load between server fleets. Nginx proxies the incoming requests and sends it to the backend servers. To configure Nginx as a load balancer, you have to add two blocks of code to the nginx configuration file.

Step 1: Open nginx.conf file

sudo vi /etc/nginx/nginx.conf

Step 2: Add the upstream group under the HTTP section. The upstream group is the group of servers which comes under the load balancer. You can give any user defined name for the group. Here am going to give the name as “web_fleet”.

Note: this configuration should be present in the HTTP section of nginx.conf file.

Step 3: Now you have to set the vhost configuration to receive traffic from a particular domain name and route it to the upstream servers. Add the following lines followed by the upstream block and save the file.

Step 4: Restart the Nginx server

sudo systemctl restart nginx

Step 5: Now, if you access your nginx server using the DNS, the request will be routed to the backend server fleet present in the upstream block.

Make sure some service is running on the backend servers you mention in the upstream block.

There are many other parameters and setting associated with the load balancing configuration. You can check the official Nginx documentation for more clarification.

Источник

Оцените статью
Adblock
detector