【问题标题】:Why permission denied occured when accessing my local website?为什么访问我的本地网站时出现权限被拒绝?
【发布时间】:2017-10-14 06:14:44
【问题描述】:

我正在使用 Linux Mint 18.2 和 docker。 目前我有 2 个来自 bitnami 的 docker 容器,1 个用于 nginx,另一个是 php-fpm。 这是我对 nginx 的 docker-compose 配置:

version: '2'

services:
  nginx:
    image: 'bitnami/nginx:latest'
    group_add:
      - www-data
    restart: always
    labels:
      kompose.service.type: nodeport
    ports:
      - '80:8080'
      - '443:8443'
    volumes:
      - 'nginx_data:/bitnami'
      - ~/Documents/nginx/nginx.conf:/bitnami/nginx/conf/nginx.conf:ro
      - ~/Documents/nginx/my_vhost.conf:/bitnami/nginx/conf/vhosts/my_vhost.conf:ro
      - /usr/share/nginx/html:/app

volumes:
  nginx_data:
    driver: local

这是我用于 php-fpm 的 docker-compose.yml :

version: '2'

services:
  php:
    tty: true # Enables debugging capabilities when attached to this container.
    image: 'bitnami/php-fpm:latest'
    labels:
      kompose.service.type: nodeport
    ports:
      - 9000:9000
    volumes:
      - /usr/share/nginx/html:/app
      - ~/Documents/nginx/nginx.conf:/bitnami/nginx/conf/nginx.conf:ro
      - ~/Documents/nginx/my_vhost.conf:/bitnami/nginx/conf/vhosts/my_vhost.conf

另外,这是我的 nginx 配置:

server {
  listen 0.0.0.0:8080;
  server_name localhost;
  root /app;
  index index.htm index.html;

  location /evodms {                                                                                                                                                  
    # First attempt to serve request as file, then                                                                                                                  
    # as directory, then fall back to displaying a 404.                                                                                                             
    # root /usr/share/nginx/html;                                                                                                                                     
    # root /var/www/html/evodms;                                                                                                                                    
    try_files $uri $uri/ /evodms/index.php?$args;                                                                                                                   
  }

  location ~ \.php$ {                                                                                                                                                 
    fastcgi_pass   unix:/var/run/php/php5.6-fpm.sock;                                                                                                       
    fastcgi_index  index.php;                                                                                                                               
    fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;                                                                                    
    include        fastcgi_params;                                                                                                                          
  }
}

我已经启动了所有容器,nginx 容器生成了用户 1001,所以我将此用户映射到 www-data,仅供参考,我的 evodms 文件夹所有权已设置为 www-data。 但我收到了这条消息:

nginx_1  | 2017/10/14 06:12:39 [error] 25#0: *1 directory index of "/app/evodms/" is forbidden, client: 172.20.0.1, server: localhost, request: "GET /evodms/ HTTP/1.1", host: "localhost"
nginx_1  | 172.20.0.1 - - [14/Oct/2017:06:12:39 +0000] "GET /evodms/ HTTP/1.1" 403 198 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"

有什么线索吗?

【问题讨论】:

  • 为什么会有两个撰写文件?
  • 我正在使用 2 个分离的 docker 图像

标签: docker nginx fpm


【解决方案1】:

您的 nginx 尝试在 evodms 文件夹中查找 index.html。因为您在 root 选项下将索引设置为 index index.htm index.html

我猜你的 evodms 是存在于你的公用文件夹下的吧?

如果你这样设置位置路径。

location /evodms {                                                                                                                                                  
   try_files $uri $uri/ /evodms/index.php?$args;                                                                                                                   
}

查看 try_files。顺序是 $uri 然后是 $uri/。 nginx 会检查 url /evodms/ 是否是一个文件夹?如果是,请将其退回。但如果不是,nginx 会尝试其他选项。

如何检查。 首先,尝试在您的 evodms 文件夹中添加文件 index.html。如果您访问它,它将显示在您的页面中,因为 nginx 成功将 evodms 定义为文件夹。

或者只是从try_files 中取出$uri/。所以 nginx 不会尝试将 evodms 定义为文件夹。它将直接重写为下一个选项。这是evodms/index.php?$args

【讨论】:

    【解决方案2】:

    您的nginx配置中/evodms的位置适用于从/evodms开始的所有请求,因此,例如,当您请求/evodms/test时,nginx首先尝试/app/evodms/test文件,然后尝试/app/evodms/test/文件夹,最后尝试/app/evodms/index.php?$args

    但是当您请求/evodms/ 时,它会尝试/app/evodms/,即/ 用于位置/evodms。在这种情况下,nginx 会尝试使用您在 index 选项中定义的索引文件。您的/app/evodms 文件夹中似乎没有index.htmlindex.htm,因此您会收到403 禁止错误。

    为了修复对<your_domain>/evodms/的请求,您应该将index.php添加到索引文件列表中:

    index index.htm index.html index.php;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-10
      • 2015-11-09
      • 2011-02-17
      • 2017-11-16
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      相关资源
      最近更新 更多