2023 年可在 Amazon Linux 上安装 Nginx

在Amazon Linux 2023上安装Nginx。

由于有机会接触到Amazon Linux 2023,所以做以下备忘录。

首先使用SSH连接到服务器。

uname -r

6.1.41-63.114.amzn2023.x86_64

安装Nginx。

dnf update
dnf -y install nginx

不使用yum或者apt-get,而是使用dnf。

nginx -v
nginx version: nginx/1.24.0

设定为即使重新启动也会自动启动。

systemctl enable nginx

Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

启动

systemctl start nginx.service
systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; preset: disabled)
     Active: active (running) since Sun 2023-09-03 14:11:18 UTC; 7s ago
    Process: 26194 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
    Process: 26197 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
    Process: 26203 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
   Main PID: 26216 (nginx)
      Tasks: 2 (limit: 1114)
     Memory: 2.2M
        CPU: 56ms
     CGroup: /system.slice/nginx.service
             ├─26216 "nginx: master process /usr/sbin/nginx"
             └─26217 "nginx: worker process"

Sep 03 14:11:18 ip-xx-xx-xx-xx.ap-northeast-1.compute.internal systemd[1]: Starting nginx.service - The nginx HTTP and reverse proxy server...
Sep 03 14:11:18 ip-xx-xx-xx-xx.ap-northeast-1.compute.internal nginx[26197]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Sep 03 14:11:18 ip-xx-xx-xx-xx.ap-northeast-1.compute.internal nginx[26197]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Sep 03 14:11:18 ip-xx-xx-xx-xx.ap-northeast-1.compute.internal systemd[1]: Started nginx.service - The nginx HTTP and reverse proxy server.

为了通过浏览器进行确认,需要稍微调整SSH设置。

Host my-nginx
    Hostname xxx.xxx.xxx.xxx
    Port 22
    User ec2-user
    ServerAliveInterval 180
    ServerAliveCountMax 120
    IdentityFile ~/.ssh/xxxxxx.pem
    LocalForward 10000 localhost:80

在进行本地主机端口转发时,当访问localhost:10000端口时,将其转发到SSH访问目标的localhost:80端口。

image.png

以上 (yǐ 。

广告
将在 10 秒后关闭
bannerAds