【问题标题】:Allow access to index.php and one public directory only, with nginx只允许使用 nginx 访问 index.php 和一个公共目录
【发布时间】:2015-05-30 06:03:44
【问题描述】:

我想允许免费访问/index.php 以及/public folder 及其所有子目录。不幸的是,无论我尝试什么,Nginx 仍然拒绝连接,无论是我还是我的脚本(嵌套在 html 模板中,他们需要访问公共文件夹才能获得一些资源,例如 css) .

当我尝试打开public 时,我得到一个403,就像所有其他路径一样。但是,index.php 一切都很好(允许访问)。 Nginx 进程由 www-data 处理,public 文件夹拥有所有良好权限。我错过了什么吗?

这是我的 nginx 配置:

server {

        server_name dev;

        listen  80;
        listen  [::]:80 ipv6only=on;

        return  301 https://$server_name$request_uri;

}

server {

        fastcgi_buffers 8 16k;
        fastcgi_buffer_size 32k;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;

        server_name dev;
        listen 443 default_server ssl;
       ssl on;
        ssl_certificate ssl/dev.cert;
        ssl_certificate_key ssl/dev.nopass.key;
        ssl_session_timeout 5m;
        #ssl_protocols TLSv1;
        ssl_prefer_server_ciphers on;
        ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+EXP;

        root /var/www/awesomeProject;
        index index.php;

        # deny everything that doesn't match another location
        location / { deny all; }

        location = / { } # need to allow GET / to internally redirect to /index.php

        location /index.php {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/tmp/php.sock;
        }

location = /public { allow all; }

}

【问题讨论】:

  • 只要location /public {} 应该可以工作。
  • 它没有:/我不明白这是怎么回事......
  • 它说:[错误]“/var/www/awesomeProject/public/”的目录索引被禁止,客户端:127.0.0.1,服务器:dev,请求:“GET /public/ HTTP/ 1.1”,主机:“开发”
  • 您想要列出或想要来自/public 的文件?需要一些真实的文件,例如/public/style.css
  • 哦! /public/style.css 有效。我现在明白了,我不知道列表是默认禁止的……我的错,我的困惑。谢谢@Alexey

标签: nginx configuration webserver


【解决方案1】:

我对 Nginx 中默认禁止列出目录这一事实感到困惑。以上配置适用于/public/style.css等真实文件。

感谢@Alexey Ten

【讨论】:

    猜你喜欢
    • 2015-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-10
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    相关资源
    最近更新 更多