
【AWS EC2】Amazon Linux2에 nginx를 설치하는 방법
2022-10-03 last update
7 minutes reading nginx EC2 AWS AmazonLinux2개요
AWS EC2(AMI: Amazon Linux 2)에 nginx 설치
환경
구축 절차
1. Amazon Linux Extras 확인
Amazon Linux2에는 nginx의 yum이 없으므로 Amazon Linux Extras에서 nginx를 찾습니다.
$ 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
2. nginx 설치
Amazon Linux Extras에서 nginx를 설치합니다.
$ sudo amazon-linux-extras install nginx1
Installed:
nginx.x86_64 1:1.16.1-1.amzn2.0.1
Dependency Installed:
gd.x86_64 0:2.0.35-26.amzn2.0.2 gperftools-libs.x86_64 0:2.6.1-1.amzn2
libXpm.x86_64 0:3.5.12-1.amzn2.0.2 nginx-all-modules.noarch 1:1.16.1-1.amzn2.0.1
nginx-filesystem.noarch 1:1.16.1-1.amzn2.0.1 nginx-mod-http-geoip.x86_64 1:1.16.1-1.amzn2.0.1
nginx-mod-http-image-filter.x86_64 1:1.16.1-1.amzn2.0.1 nginx-mod-http-perl.x86_64 1:1.16.1-1.amzn2.0.1
nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.amzn2.0.1 nginx-mod-mail.x86_64 1:1.16.1-1.amzn2.0.1
nginx-mod-stream.x86_64 1:1.16.1-1.amzn2.0.1
Complete!
38 nginx1=latest enabled [ =stable ]
$ nginx -v
nginx version: nginx/1.16.1
3. nginx 시작
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 Mon 2020-03-30 15:38:21 JST; 7s ago
$ sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
$ systemctl is-enabled nginx
enabled
보안 그룹에서 80을 열면 EC2의 공용 IP에서 nginx의 기본 화면이 표시됩니다.
참고
$ 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
$ sudo amazon-linux-extras install nginx1
Installed:
nginx.x86_64 1:1.16.1-1.amzn2.0.1
Dependency Installed:
gd.x86_64 0:2.0.35-26.amzn2.0.2 gperftools-libs.x86_64 0:2.6.1-1.amzn2
libXpm.x86_64 0:3.5.12-1.amzn2.0.2 nginx-all-modules.noarch 1:1.16.1-1.amzn2.0.1
nginx-filesystem.noarch 1:1.16.1-1.amzn2.0.1 nginx-mod-http-geoip.x86_64 1:1.16.1-1.amzn2.0.1
nginx-mod-http-image-filter.x86_64 1:1.16.1-1.amzn2.0.1 nginx-mod-http-perl.x86_64 1:1.16.1-1.amzn2.0.1
nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.amzn2.0.1 nginx-mod-mail.x86_64 1:1.16.1-1.amzn2.0.1
nginx-mod-stream.x86_64 1:1.16.1-1.amzn2.0.1
Complete!
38 nginx1=latest enabled [ =stable ]
$ nginx -v
nginx version: nginx/1.16.1
$ 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 Mon 2020-03-30 15:38:21 JST; 7s ago
$ sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
$ systemctl is-enabled nginx
enabled