首页 > 解决方案 > 无法在 ubuntu AWS EC2 服务器上访问 nginx

问题描述

我正在尝试启动一个 Python 网络应用程序,就像我通常做的一样(并不是说我完全知道我在做什么)。通常,当我在服务器上运行 nginx 并在浏览器中访问 IP 时,我会看到“错误网关”。无论出于何种原因,我现在只是超时。

编辑:我期待一个坏网关,我什么也没得到

提前致谢,

我没有对默认配置文件做任何事情......我etc/nginx/sites-available/default看起来像这样

server {
    listen 80;
    server_name ec2-52-36-167-131.us-west-2.compute.amazonaws.com;
    access_log  /var/log/nginx/test.log;

    location / {
        proxy_pass http://127.0.0.1:8000/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

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 Fri 2020-06-19 02:06:09 UTC; 8s ago
     Docs: man:nginx(8)
  Process: 9149 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
  Process: 9161 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 9152 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
 Main PID: 9162 (nginx)
    Tasks: 2 (limit: 1152)
   CGroup: /system.slice/nginx.service
           ├─9162 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
           └─9163 nginx: worker process

Jun 19 02:06:09 ip-172-31-25-6 systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jun 19 02:06:09 ip-172-31-25-6 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 19 02:06:09 ip-172-31-25-6 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jun 19 02:06:09 ip-172-31-25-6 systemd[1]: Started A high performance web server and a reverse proxy server.

当我curl -I ec2-52-36-167-131.us-west-2.compute.amazonaws.com在服务器上时,我得到了我期望的坏网关,但在我的本地机器上我得到了超时。

标签: amazon-web-servicesubuntunginx

解决方案


解决了,这是 AWS 安全组中的一个问题。

在这里找到它:Ubuntu 18 上的 nginx 网站未在公共 IP 上加载


推荐阅读