Php 根目录下禁止使用NGINX 403

Php 根目录下禁止使用NGINX 403,php,amazon-web-services,nginx,bitnami,amazon-lightsail,Php,Amazon Web Services,Nginx,Bitnami,Amazon Lightsail,使用从Bitnami安装的Linux/NGINX在AWS Lightsail上设置站点 根文件夹(/opt/bitnami/nginx/html)默认包含index.html,一切正常。但是,将该索引文件替换为index.php会在chrome中返回403并记录以下错误 *42 directory index of "/opt/bitnami/nginx/html/" is forbidden php正在执行 通过直接指向Index.php的路径(site.com/Index.php),可以在

使用从Bitnami安装的Linux/NGINX在AWS Lightsail上设置站点

根文件夹(/opt/bitnami/nginx/html)默认包含index.html,一切正常。但是,将该索引文件替换为index.php会在chrome中返回403并记录以下错误

*42 directory index of "/opt/bitnami/nginx/html/" is forbidden
php正在执行

通过直接指向Index.php的路径(site.com/Index.php),可以在浏览器中访问Index.php

我的配置文件nginx.conf的内容未经修改,如下所示

user  daemon daemon;
worker_processes  auto;

error_log  "/opt/bitnami/nginx/logs/error.log";

events {
    use                 epoll;
    worker_connections  1024;
    multi_accept        on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    client_body_temp_path  "/opt/bitnami/nginx/tmp/client_body" 1 2;
    proxy_temp_path "/opt/bitnami/nginx/tmp/proxy" 1 2;
    fastcgi_temp_path "/opt/bitnami/nginx/tmp/fastcgi" 1 2;
    scgi_temp_path "/opt/bitnami/nginx/tmp/scgi" 1 2;
    uwsgi_temp_path "/opt/bitnami/nginx/tmp/uwsgi" 1 2;

    access_log  "/opt/bitnami/nginx/logs/access.log";

    sendfile        on;

    keepalive_timeout  65;

    gzip on;
    gzip_http_version 1.1;
    gzip_comp_level 2;
    gzip_proxied any;
    gzip_vary on;
    gzip_types text/plain
               text/xml
               text/css
               text/javascript
               application/json
               application/javascript
               application/x-javascript
               application/ecmascript
               application/xml
               application/rss+xml
               application/atom+xml
               application/rdf+xml
               application/xml+rss
               application/xhtml+xml
               application/x-font-ttf
               application/x-font-opentype
               application/vnd.ms-fontobject
               image/svg+xml
               image/x-icon
               application/atom_xml;

    gzip_buffers 16 8k;

    add_header X-Frame-Options SAMEORIGIN;

    ssl_prefer_server_ciphers  on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS;

    include "/opt/bitnami/nginx/conf/bitnami/bitnami.conf";

}
包括“/opt/bitnami/nginx/conf/bitnami/bitnami.conf”的内容如下

# HTTP server

server {
    listen       80;
    server_name  localhost;

    include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";

}
location ~ \.php$ {
    root           html;
    fastcgi_read_timeout 300;
    fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include        fastcgi_params;
}
location / {
    root   html;
    index  index.php;
}

location ~ \.php$ {
    root           html;
    fastcgi_read_timeout 300;
    fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include        fastcgi_params;
}
包括“/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf”的内容如下

# HTTP server

server {
    listen       80;
    server_name  localhost;

    include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";

}
location ~ \.php$ {
    root           html;
    fastcgi_read_timeout 300;
    fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include        fastcgi_params;
}
location / {
    root   html;
    index  index.php;
}

location ~ \.php$ {
    root           html;
    fastcgi_read_timeout 300;
    fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include        fastcgi_params;
}
注意:我还尝试向上面添加
index.php
。 关于这里可能发生的事情有什么想法吗

注意:疑难解答,我尝试了上述nginx.config文件的精简替代方案,它解决了403错误,但在访问根目录时除了下载index.php文件外,什么都不做

user  daemon daemon;
worker_processes  auto;

error_log  "/opt/bitnami/nginx/logs/error.log";



events {
    use                 epoll;
    worker_connections  1024;
    multi_accept        on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    client_body_temp_path  "/opt/bitnami/nginx/tmp/client_body" 1 2;
    proxy_temp_path "/opt/bitnami/nginx/tmp/proxy" 1 2;
    fastcgi_temp_path "/opt/bitnami/nginx/tmp/fastcgi" 1 2;
    scgi_temp_path "/opt/bitnami/nginx/tmp/scgi" 1 2;
    uwsgi_temp_path "/opt/bitnami/nginx/tmp/uwsgi" 1 2;

    access_log  "/opt/bitnami/nginx/logs/access.log";

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   html;
            index  index.php;
        }

    }

}
通过更新“/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf”解决,如下所示

# HTTP server

server {
    listen       80;
    server_name  localhost;

    include "/opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf";

}
location ~ \.php$ {
    root           html;
    fastcgi_read_timeout 300;
    fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include        fastcgi_params;
}
location / {
    root   html;
    index  index.php;
}

location ~ \.php$ {
    root           html;
    fastcgi_read_timeout 300;
    fastcgi_pass   unix:/opt/bitnami/php/var/run/www.sock;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $request_filename;
    include        fastcgi_params;
}
我承认,这不是我最自豪的时刻