Amazon EC2 上的 Nginx 默认无法打开 index.php

Can't open index.php by default with Nginx on Amazon EC2

当我转到我的 Amazon EC2 public IP 时,我无法访问 index.php

我安装了 php5-fpmphp5-mysql

打开http://publicIP/index.php时显示404错误。
我的 index.php 文件在 /var/www/html.

以下内容为/etc/nginx/sites-enabled/

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name _;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }
    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
    #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
    #
    #       # With php5-cgi alone:
            fastcgi_pass 127.0.0.1:9000;
    #       # With php5-fpm:
    #       fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

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

只需使用以下命令从启用站点的文件夹中删除 index.html sudo rm index.html 然后重新启动 nginx sudo service nginx restart。现在,当您使用命令 sudo nginx -t 进行测试时。它应该显示成功。