linux - NGINX 不显示 Amazon EC2 实例上的默认页面

标签 linux nginx amazon-ec2

我在 Fedora 上安装了 nginx。但是不知道为什么通过浏览器请求服务器IP获取不到默认的nginx页面。我的请求因超时而中断。

但是 nginx 正在运行。

$ sudo service nginx status
nginx (pid  20372) is running...

我默认生成的配置是

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm;

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  localhost;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        }

        # redirect server error pages to the static page /40x.html
        #
        error_page 404 /404.html;
            location = /40x.html {
        }

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

# Settings for a TLS enabled server.
#
#    server {
#        listen       443 ssl;
#        listen       [::]:443 ssl;
#        server_name  localhost;
#        root         /usr/share/nginx/html;
#
#        ssl_certificate "/etc/pki/nginx/server.crt";
#        ssl_certificate_key "/etc/pki/nginx/private/server.key";
#        # It is *strongly* recommended to generate unique DH parameters
#        # Generate them with: openssl dhparam -out /etc/pki/nginx/dhparams.pem 2048
#        #ssl_dhparam "/etc/pki/nginx/dhparams.pem";
#        ssl_session_cache shared:SSL:1m;
#        ssl_session_timeout  10m;
#        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#        ssl_ciphers HIGH:SEED:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!RSAPSK:!aDH:!aECDH:!EDH-DSS-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!SRP;
#        ssl_prefer_server_ciphers on;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }
#
#        error_page 404 /404.html;
#            location = /40x.html {
#        }
#
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
#        }
#    }

}

我不知道发生了什么。/var/log/nginx/access.log 和/var/log/nginx/access.log 也是空的。请帮助...

最佳答案

在 Amazon EC2 上,您需要打开防火墙以允许从浏览器到实例的传入 HTTP 连接。

  1. 登录亚马逊网络控制台
  2. 转到 EC2
  3. 找到你的实例
  4. 点击其安全组
  5. 点击入站标签
  6. 点击编辑
  7. Add Rule -> HTTP,设置Source字段为My Ip

更改将立即生效。

请注意,如果您从非固定 IP(咖啡店 wifi)访问您的实例,则每次连接时都需要更改源 IP 地址并分配一个新的 IP 地址。因此,如果它有效,然后过了一会儿,它似乎挂起,这可能就是原因。

如果您还提供 HTTPS,您还需要添加特定规则。

关于linux - NGINX 不显示 Amazon EC2 实例上的默认页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37481101/

相关文章:

python - 如何使用相机矩阵使图像不失真?

linux - 使用 Dockerfile ENTRYPOINT 找不到 exec

php - nginx - 让 PHP 通过 TCP 而不是套接字

windows - 从自定义 AMI 自动登录启动多个 ec2 windows 服务器

linux - 我以前从未设置过 cron 作业,但希望每天在我的服务器上运行一个 Python 脚本 15 分钟

linux - 如何以非交互方式使用命令 'at'

ruby-on-rails - 好的 unicorn + nginx +帽子部署方法

java - 为什么 Nginx 以相反的顺序提供客户端 SSL DN?

amazon-web-services - "aws s3 ls"命令抛出 "InvalidRequest"错误消息。如何解决?

mysql - 将 sql 文件导入 AWS RDS