如何在【AWS EC2】Amazon Linux2上安装nginx
简而言之
在AWS EC2上安装nginx(AMI: Amazon Linux 2).
环境 –
-
- AWS EC2
OS: Amazon Linux 2
AMI ID: amzn2-ami-hvm-2.0.20200304.0-x86_64-gp2
建造过程
确认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
安装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
启动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的默认页面。
请用中文给出以下内容的表达:
参考
-
- Amazon Linux 2にExtrasレポジトリからNginxをインストールする
-
- Amazon Linux Extrasで楽々パッケージ管理
- CentOS 7へNginxをインストールして最短でサイトが表示できる手順