If you're using AWS Linux2, you have to install nginx from the AWS "Extras Repository". To see a list of the packages available:

# View list of packages to install
amazon-linux-extras list

You'll see a list similar to:

0  ansible2   disabled  [ =2.4.2 ]
1  emacs   disabled  [ =25.3 ]
2  memcached1.5   disabled  [ =1.5.1 ]
3  nginx1.12   disabled  [ =1.12.2 ]
4  postgresql9.6   disabled  [ =9.6.6 ]
5  python3   disabled  [ =3.6.2 ]
6  redis4.0   disabled  [ =4.0.5 ]
7  R3.4   disabled  [ =3.4.3 ]
8  rust1   disabled  [ =1.22.1 ]
9  vim   disabled  [ =8.0 ]
10  golang1.9   disabled  [ =1.9.2 ]
11  ruby2.4   disabled  [ =2.4.2 ]
12  nano   disabled  [ =2.9.1 ]
13  php7.2   disabled  [ =7.2.0 ]
14  lamp-mariadb10.2-php7.2   disabled  [ =10.2.10_7.2.0 ]

Use the amazon-linux-extras install command to install it, like:

sudo amazon-linux-extras install nginx1.12

More details are here: https://aws.amazon.com/amazon-linux-2/faqs/.

Answer from Dan Sterrett on Stack Overflow
Top answer
1 of 4
64

If you're using AWS Linux2, you have to install nginx from the AWS "Extras Repository". To see a list of the packages available:

# View list of packages to install
amazon-linux-extras list

You'll see a list similar to:

0  ansible2   disabled  [ =2.4.2 ]
1  emacs   disabled  [ =25.3 ]
2  memcached1.5   disabled  [ =1.5.1 ]
3  nginx1.12   disabled  [ =1.12.2 ]
4  postgresql9.6   disabled  [ =9.6.6 ]
5  python3   disabled  [ =3.6.2 ]
6  redis4.0   disabled  [ =4.0.5 ]
7  R3.4   disabled  [ =3.4.3 ]
8  rust1   disabled  [ =1.22.1 ]
9  vim   disabled  [ =8.0 ]
10  golang1.9   disabled  [ =1.9.2 ]
11  ruby2.4   disabled  [ =2.4.2 ]
12  nano   disabled  [ =2.9.1 ]
13  php7.2   disabled  [ =7.2.0 ]
14  lamp-mariadb10.2-php7.2   disabled  [ =10.2.10_7.2.0 ]

Use the amazon-linux-extras install command to install it, like:

sudo amazon-linux-extras install nginx1.12

More details are here: https://aws.amazon.com/amazon-linux-2/faqs/.

2 of 4
20

At the time of writing, the latest version of nginx available from the AWS yum repo is 1.8.

The best thing to do for now is to build any newer version from source.

The AWS Linux AMI already has the necessary build tools.

For example, based on the Nginx 1.10 (I've assumed you're logged in as the regular ec2-user. Anything needing superuser rights is preceded with sudo)

cd /tmp #so we can clean-up easily
wget http://nginx.org/download/nginx-1.10.0.tar.gz
tar zxvf nginx-1.10.0.tar.gz && rm -f nginx-1.10.0.tar.gz
cd nginx-1.10.0
sudo yum install pcre-devel openssl-devel #required libs, not installed by default
./configure \
  --prefix=/etc/nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --pid-path=/var/run/nginx.pid \
  --lock-path=/var/run/nginx.lock \
  --with-http_ssl_module \
  --with-http_v2_module \
  --user=nginx \
  --group=nginx
make
sudo make install
sudo groupadd nginx
sudo useradd -M -G nginx nginx
rm -rf nginx-1.10.0

You'll then want a service file, so that you can start/stop nginx, and load it on boot.

Here's one that matches the above config. Put it in /etc/rc.d/init.d/nginx:

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  NGINX is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /etc/nginx/nginx.conf
# config:      /etc/sysconfig/nginx
# pidfile:     /var/run/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/etc/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/etc/nginx/nginx.conf"

[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx

lockfile=/var/run/nginx.lock

make_dirs() {
   # make required directories
   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
   if [ -z "`grep $user /etc/passwd`" ]; then
       useradd -M -s /bin/nologin $user
   fi
   options=`$nginx -V 2>&1 | grep 'configure arguments:'`
   for opt in $options; do
       if [ `echo $opt | grep '.*-temp-path'` ]; then
           value=`echo value" ]; then
               # echo "creating" $value
               mkdir -p $value && chown -R $user $value
           fi
       fi
   done
}

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    make_dirs
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    sleep 1
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

Set the service file to be executable:

sudo chmod 755 /etc/rc.d/init.d/nginx

Now you can start it with:

sudo service nginx start

To load it automatically on boot:

sudo chkconfig nginx on

Finally, don't forget to edit /etc/nginx/nginx.conf to match your requirements and run sudo service nginx reload to refresh the changes.

🌐
Medium
medium.com › @eikachiu › install-nginx-on-to-aws-ec2-lightsail-amazon-linux-2-c0a5bbae5a4f
Install nginx on to AWS EC2 / Lightsail Amazon Linux 2 | by Eika Chiu | Medium
March 8, 2024 - [ec2-user@ip-172-26-11-240 ~]$ sudo amazon-linux-extras install nginx1 Installing nginx Failed to set locale, defaulting to C Loaded plugins: extras_suggestions, langpacks, priorities, update-motd Cleaning repos: amzn2-core amzn2extra-docker ...
🌐
Medium
medium.com › @sharnellgrant › installing-nginx-on-aws-ec2-c0828e2eb914
Installing Nginx on AWS EC2. This is week 6 project at Level Up in… | by Sharnell Grant | Medium
May 17, 2023 - Once the instance launches it will automatically run the script and install nginx. After step 2, scroll down to advanced details: ... Locate the user data input box. Here is where you will input the script. ... #!/bin/bash sudo yum update -y sudo amazon-linux-extras install nginx1 ...
🌐
GeeksforGeeks
geeksforgeeks.org › cloud computing › how-to-install-nginx-on-amazon-linux
How To Install Nginx On Amazon linux ? - GeeksforGeeks
July 23, 2025 - The following install the nginx software: sudo amazon-linux-extras install nginx1.12 · With the help of the above command, we can update all the existing packages, Installing nginx into the server.
🌐
DZone
dzone.com › data engineering › databases › nginx yum proxy repository setup for amazon linux ec2
NGINX Yum Proxy Repository Setup for Amazon Linux EC2
September 28, 2020 - ###Install NGINX · 2 · $ sudo amazon-linux-extras install nginx1 -y · 3 · 4 · 5 · ###Start, Enable and check the status of nginx server · 6 · $ systemctl start nginx · 7 · $ systemctl enable nginx · 8 · $ systemctl status nginx · ...
🌐
DEV Community
dev.to › devops_den › how-to-install-nginx-on-an-amazon-ec2-instance-3i50
How to install Nginx on an Amazon EC2 instance - DEV Community
June 19, 2024 - Install Nginx · sudo amazon-linux-extras install nginx1.12 -y Start and Enable Nginx: sudo systemctl start nginx sudo systemctl enable nginx · Read More about Nginx · ThankYou · Subscribe · For further actions, you may consider blocking ...
🌐
DBASolved
dbasolved.com › home › installing nginx on aws ec2 instance
Installing Nginx on AWS EC2 instance - DBASolved
April 28, 2022 - After logging in as the root user, you’ll need to run “amazon-linux-extras” to get nginx installed.
Find elsewhere
🌐
Educative
educative.io › answers › how-to-get-started-with-aws-ec2
How to get started with AWS EC2
Now let’s install NginX on this machine. NginX is available from the AWS extras repository.
🌐
CloudKatha
cloudkatha.com › home › how to install nginx on amazon linux 2 instance
How to Install Nginx on Amazon Linux 2 Instance - CloudKatha
June 21, 2023 - When writing this post, Nginx is available in amazon-linux-extras repository and we will install it from there only on Amazon Linux 2.
Top answer
1 of 1
1

It all depends whether you are on Amazon Linux 1 (2018.03) or Amazon Linux 2.

Check the /etc/os-release file to find out which one you have.

Amazon Linux 1

/etc/os-release contains:

NAME="Amazon Linux AMI"
VERSION="2018.03"
ID="amzn"
ID_LIKE="rhel fedora"
VERSION_ID="2018.03"
PRETTY_NAME="Amazon Linux AMI 2018.03"
ANSI_COLOR="0;33"
CPE_NAME="cpe:/o:amazon:linux:2018.03:ga"
HOME_URL="http://aws.amazon.com/amazon-linux-ami/"

The AWS repo for Amazon Linux 1 only has nginx version 1.14.1:

0» yum info nginx
Loaded plugins: priorities, update-motd, upgrade-helper
1070 packages excluded due to repository priority protections
Available Packages
Name        : nginx
Arch        : x86_64
Epoch       : 1
Version     : 1.14.1
Release     : 2.34.amzn1

Amazon Linux 2

/etc/os-release contains:

NAME="Amazon Linux"
VERSION="2"
ID="amzn"
ID_LIKE="centos rhel fedora"
VERSION_ID="2"
PRETTY_NAME="Amazon Linux 2"
ANSI_COLOR="0;33"
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
HOME_URL="https://amazonlinux.com/"

At the time of writing, AL2 only has nginx 1.12.2:

» amazon-linux-extras list | grep nginx
  4  nginx1.12                available    [ =1.12.2 ]

Installing stock version

Installing the stock version is easy. For AL1, do yum install nginx and for AL2 do amazon-linux-extras install nginx1.12.

Compile it yourself

To run a cutting edge version of nginx, you probably need to compile it yourself or ask AWS to update their packages. To compile nginx yourself, see the excellent instructions by Lee Benson here: https://stackoverflow.com/questions/37082406/how-to-install-nginx-1-9-15-on-amazon-linux-disto

🌐
Bobcares
bobcares.com › blog › install-nginx-on-amazon-linux
How to Install Nginx On Amazon Linux
October 27, 2025 - sudo yum update Then install Nginx using: sudo amazon-linux-extras install nginx1.12 · Start and Enable Nginx Run commands to start Nginx, enable it at boot, and check its status: sudo systemctl start nginx sudo systemctl enable nginx sudo ...
🌐
GitHub
gist.github.com › nrollr › 56e933e6040820aae84f82621be16670
Install PHP and NGINX on Amazon Linux AMI · GitHub
This no longer works on the latest Amazon Linux images, as nginx isn't included in the default packages. See https://stackoverflow.com/questions/37082406/how-to-install-nginx-1-9-15-on-amazon-linux-disto
🌐
GitHub
gist.github.com › keidarcy › c2871047c4dc73427b41b5be93fba743
Amazon Linux 2 - nginx/httpd · GitHub
user_data = <<-EOL #!/bin/bash sudo amazon-linux-extras install nginx1 sudo systemctl start nginx sudo systemctl status nginx echo "Hello World from ec2" > /usr/share/nginx/html EOL
🌐
GitHub
gist.github.com › sshymko › 194667d199080792b73d03920065f2a8
Install Nginx and PHP-FPM on Amazon Linux 2 from Amazon Linux Extras · GitHub
Install Nginx and PHP-FPM on Amazon Linux 2 from Amazon Linux Extras - install_nginx_php7_amzn2_extra.sh
🌐
d:constructed
ddmanley.wordpress.com › 2019 › 06 › 03 › how-to-install-nginx-on-amazon-linux-2
How-to install Nginx on Amazon Linux 2 – d:constructed
June 7, 2019 - Next, we’ll run: sudo amazon-linux-extras install nginx1.12 (you must use the version number otherwise the install will fail). Once installed, you will see a screen similar to the one below.
🌐
GeeksforGeeks
geeksforgeeks.org › cloud computing › how-to-install-nginx-on-amazon-linux
How To Install Nginx On Amazon linux ? - GeeksforGeeks
July 23, 2025 - The following install the nginx software: sudo amazon-linux-extras install nginx1.12 · With the help of the above command, we can update all the existing packages, Installing nginx into the server.
Top answer
1 of 2
129

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
2 of 2
43

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.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

Something like this...

#!/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://{my_bucket}/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.

🌐
Medium
medium.com › @devdiaryacademy › how-to-install-nginx-on-an-amazon-linux-2-instance-developer-diary-6007e9d7e141
How to Install Nginx on an Amazon Linux 2 Instance — Developer Diary | by Developer Diary | Medium
February 10, 2026 - Now that our system has been upgraded, we can begin installing Nginx. Execute this command: ... By using amazon-linux-extras, we can easily install the latest stable version of Nginx available for Amazon Linux 2.