【问题标题】:Can't open index.php by default with Nginx on Amazon EC2默认情况下无法在 Amazon EC2 上使用 Nginx 打开 index.php
【发布时间】:2015-08-14 09:22:11
【问题描述】:

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

我安装了php5-fpmphp5-mysql

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

以下是/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;
    #}
}

【问题讨论】:

  • 您发布的配置 - 您如何将其包含到主要的 nginx 配置中?很可能只是被跳过了。
  • 那我该怎么办? @RobbieAverill 我应该检查我的其他 nginx 配置吗?
  • 故意破坏它(语法错误或其他什么)然后运行nginx -t 来测试语法并确保它说有问题
  • 我犯了一个语法错误然后测试,它显示:nginx: configuration file /etc/nginx/nginx.conf test failed
  • 现在我得到:nginx: [emerg] unknown directive "<!DOCTYPE" in /etc/nginx/sites-enabled/index.html:6 nginx: configuration file /etc/nginx/nginx.conf test failed@RobbieAverill

标签: php nginx amazon-ec2


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2016-02-28
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多