Nginx 运行 但不在端口 80 上服务 | Ubuntu 20.04 | EC2 |电子文件系统

Nginx running but not serving on port 80 | Ubuntu 20.04 | EC2 | EFS

我在 AWS 的 EC2 实例上 运行ning Ubuntu 20.04。由于某种原因,当服务器重新启动时,Nginx 启动但端口 80 上没有服务列表。当使用 SSH 时,我可以 运行 sudo service Nginx reload 并且一切都开始 运行ning。感谢想法、帮助和建议。

重新启动后查看输出。

ubuntu@ip-xxx-xxx-xxx-xxx:~$ ps aux | grep nginx
root         504  0.0  0.1  57184  1460 ?        Ss   10:21   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data     508  0.0  0.5  57944  5368 ?        S    10:21   0:00 nginx: worker process
ubuntu      1039  0.0  0.2   8160  2572 pts/0    S+   10:44   0:00 grep --color=auto nginx
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo service nginx status
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-02-09 10:21:59 UTC; 8min ago
       Docs: man:nginx(8)
    Process: 460 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 503 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 504 (nginx)
      Tasks: 2 (limit: 1164)
     Memory: 9.2M
     CGroup: /system.slice/nginx.service
             ├─504 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─508 nginx: worker process
Feb 09 10:21:59 ip-xxx-xxx-xxx-xxx systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 09 10:21:59 ip-xxx-xxx-xxx-xxx systemd[1]: Started A high performance web server and a reverse proxy server.
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo netstat -tanpl|grep nginx
ubuntu@ip-xxx-xxx-xxx-xxx:~$ sudo netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      397/systemd-resolve 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      628/sshd: /usr/sbin 
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1/init              
tcp6       0      0 :::22                   :::*                    LISTEN      628/sshd: /usr/sbin 
tcp6       0      0 :::111                  :::*                    LISTEN      1/init              
udp        0      0 xxx.xxx.xxx.xxx           0.0.0.0:*                           397/systemd-resolve 
udp        0      0 xxx.xxx.xxx.xxx:68        0.0.0.0:*                           394/systemd-network 
udp        0      0 0.0.0.0:111             0.0.0.0:*                           1/init              
udp6       0      0 :::111                  :::*                                1/init             

更新 1

这似乎是 EFS 的问题。 Nginx 配置保存在 EFS 卷上,Nginx 在挂载 EFS 卷之前加载。我会继续研究和阅读,后续更新。

Nginx 根据 /lib/systemd/system/ 中设置的配置加载服务(路径可能会根据 OS 版本而改变)。

Nginx 似乎在 Ubuntu 在启动时安装网络驱动器之前启动。因为 Nginx 被告知从 EFS 卷上的目录加载所有配置,所以它无法在启动时加载配置,因为它们在文件系统完成安装之前不存在。

这可以通过告诉 Nginx 在启动之前等待特定的文件系统被挂载来解决。

  1. 通过运行编辑服务文件: Sudo nano /lib/systemd/system/nginx.service

  2. 在 [Service] 部分下添加以下行,根据需要修改挂载目标: After=network.target var-www\x2defs.mount

如果您不知道挂载目标,可以执行以下操作来查找,将 dir 替换为您将驱动器挂载到的目录。

systemctl list-units --type=mount | grep /var/www

文章 / Post 我在哪里找到了解决问题的信息:https://unix.stackexchange.com/questions/246935/set-systemd-service-to-execute-after-fstab-mount