【问题标题】:Nginx running but not serving on port 80 | Ubuntu 20.04 | EC2 | EFSNginx 正在运行但不在端口 80 上提供服务 | Ubuntu 20.04 | EC2 | EFS
【发布时间】:2021-05-12 23:52:10
【问题描述】:

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

重新启动后查看输出。

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 卷挂载之前加载。我将继续调查和阅读,后续更新。

【问题讨论】:

  • 您需要打开 80 端口进行连接。您可以通过编辑 ec2 安全组来执行此操作。 Nginx 配置没有错误。

标签: amazon-web-services ubuntu nginx amazon-ec2 amazon-efs


【解决方案1】:

Nginx 根据/lib/systemd/system/ 中设置的配置加载服务(路径可能因操作系统版本而异)。

在 Ubuntu 启动时挂载网络驱动器之前,Nginx 似乎已经启动。因为 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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-01
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2017-12-25
    • 1970-01-01
    • 2020-03-29
    • 1970-01-01
    相关资源
    最近更新 更多