Skip to content

Instantly share code, notes, and snippets.

@keidarcy
Last active January 6, 2023 00:06
Show Gist options
  • Save keidarcy/c2871047c4dc73427b41b5be93fba743 to your computer and use it in GitHub Desktop.
Save keidarcy/c2871047c4dc73427b41b5be93fba743 to your computer and use it in GitHub Desktop.
Amazon Linux 2 - nginx/httpd

Nginx

user data

  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

Search amazon-linux-extras

$ yum search nginx
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
31 packages excluded due to repository priority protections
============================================================ N/S matched: nginx =============================================================
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver

  Name and summary matches only, use "search all" for everything.

$ amazon-linux-extras list | grep nginx
 38  nginx1                   available    [ =stable ]

$ amazon-linux-extras info nginx1
nginx1 recommends nginx                      # yum install nginx

Install nginx

$ 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 amzn2extra-kernel-5.10 amzn2extra-nginx1
17 metadata files removed
6 sqlite files removed
0 metadata files removed
.....

$ nginx -v
nginx version: nginx/1.22.0

Start nginx

$ sudo systemctl start nginx
$ sudo systemctl status nginx
* nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2023-01-05 23:05:20 UTC; 5s ago
  Process: 3450 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 3446 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 3445 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 3452 (nginx)
   CGroup: /system.slice/nginx.service
           |-3452 nginx: master process /usr/sbin/nginx
           `-3453 nginx: worker process

Failed to set locale, defaulting to C

export LC_ALL=C

httpd

user data

  user_data = <<-EOL
		#!/bin/bash
		yum update -y
		yum install -y httpd
		systemctl start httpd
		systemctl enable httpd
		echo "Hello World from EC2" > /var/www/html/index.html
		EOL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment