NGINX 403禁止在根

时间:2019-03-11 07:12:17

标签: 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

Index.php仅执行<?php phpinfo(); ?>

在浏览器中直接指向Index.php的路径即可访问它(site.com/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";

}

包含的内容“ /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;
}

注意:我还尝试将index 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;
        }

    }

}

1 个答案:

答案 0 :(得分:0)

如下更新“ /opt/bitnami/nginx/conf/bitnami/phpfastcgi.conf ”来解决...

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;
}

我承认,这不是我最骄傲的时刻。