默认情况下,无法在Amazon EC2上使用Nginx打开index.php

时间:2015-08-12 01:30:29

标签: php nginx amazon-ec2

当我访问我的Amazon EC2公共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;
    #}
}

1 个答案:

答案 0 :(得分:0)

只需使用支持已启用网站的文件夹中的index.html即可 sudo rm index.html 然后重新启动nginx sudo service nginx restart。现在,当您使用命令sudo nginx -t进行测试时。它应该显示成功。