开发者社区> 问答> 正文

权限被拒绝Nginx Docker

I'm using docker compose to boot up a development workspace, consisting of php, nginx and mysql. Everything boots, static html get's served, but when trying to start a laravel app, i get the following error:

The stream or file "/home/html/storage/logs/laravel-2019-06-10.log" could not be opened: failed to open stream: Permission denied

I searched around and it looked like a permissions issue? Do note, that the docker with just the database and the build in php server does seem to work.

My docker-compose.yml

version: "3"
services:

  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: "root"
    ports:
      - 3306:3306

  php-fpm:
    image: php:7.3-fpm-alpine
    links:
      - db
    volumes:
      - "./:/home/html/"

  nginx:
    image: nginx:1-alpine
    ports:
      - "8080:80"
    links:
      - php-fpm

    volumes:
      - "./site.conf:/etc/nginx/conf.d/default.conf"
      - "./:/home/html/"

My nginx config:

server {
    index index.php index.html;
    listen 80  default_server;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /home/html/public;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }
}

遇到了同样的问题,在CSDN看到了,希望阿里云团队能够给出正确、标准的答案~请查看

展开
收起
刘刚_ 2020-05-23 21:04:53 1007 0
1 条回答
写回答
取消 提交回答
  • 把宿主机的一个目录挂载到容器中的一个目录,当访问容器中的这个目录时,出现如下问题: 2018/06/29 02:13:42 [emerg] 1#1: mkdir() "/data/nginx/tmp-test" failed (13: Permission denied) nginx: [emerg] mkdir() "/data/nginx/tmp-test" failed (13: Permission denied)

    2018/06/29 02:17:48 [emerg] 1#1: chown("/data/nginx/tmp-test", 101) failed (13: Permission denied) nginx: [emerg] chown("/data/nginx/tmp-test", 101) failed (13: Permission denied)

    无法访问目录,权限拒绝。该问题通常在centos7下出现。或者一个容器启动成功后,里面的服务无法成功访问,这是因为centos7中的安全模块selinux把权限禁掉了,一般的解决方案有以下两种:

    (1)临时关闭selinux 直接在centos服务器上执行以下命令即可。执行完成以后建议重新docker run。 setenforce 0

    (2)给容器加权限 在docker run时给该容器加权限,加上以下参数即可: --privileged=true

    2021-02-22 19:11:50
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Docker 网络深度解读 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载