docker - 为什么访问我的本地网站时发生权限被拒绝?

标签 docker nginx fpm

我正在使用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

这是我的docker-compose.yml for php-fpm:
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"

有什么线索吗?

最佳答案

您的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定义为文件夹。

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

关于docker - 为什么访问我的本地网站时发生权限被拒绝?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46741514/

相关文章:

postgresql - Docker-Compose postgres 升级 initdb : error: directory "/var/lib/postgresql/data" exists but is not empty

java - 如何使用配置文件在 docker 中启动 spring boot 应用程序?

nginx - 在后台更新 nginx 缓存

ruby-on-rails - 如何在 Nginx 服务器上的 AWS 中使用 Https?

php - Laravel 5.4.36无法在AWS ECS容器上注册新用户正常工作

php - 如何在不安装 Apache 2 的情况下卸载 php7.2-fpm(在 LEMP 机器上)

php - 如何设置php-fpm多线程工作?

python - 为什么找不到Dockerfile?

linux - 针对 docker 容器执行时 Bash 脚本失败

python - django 减少查询加载时间