禁止Dockerized Nginx访问

时间:2018-07-10 21:44:49

标签: php docker nginx dockerfile docker-toolbox

我一直试图遵循有关使用Docker构建一个典型的Web-Dev Stack的教程,其中包括PHP,Nginx和MySql。

可以在这里找到Git存储库: https://github.com/osteel/docker-tutorial-2

每当我尝试使用Docker Toolbox访问http://192.168.99.100:80时,都会出现403错误。

Docker-Compose.yml:

version: "2.1"

services:
   nginx:
      build: ./nginx/
      ports:
          - 80:80
      volumes:
          - "${PROJECT_ROOT}:/var/www/html:ro"
      networks:
          - server
      depends_on:
          - php

   php:
      build: ./php/
      expose:
          - 9000
      volumes:
          - "${PROJECT_ROOT}:/var/www/html"
      networks:
          - database
          - server
      depends_on:
          - mysql

   mysql:
      image: mysql:latest
      volumes:
          - data:/var/lib/mysql
      networks:
          - database
      environment:
          MYSQL_ROOT_PASSWORD: "${DB_ROOT_PASSWORD}"
          MYSQL_DATABASE: "${DB_NAME}"
          MYSQL_USER: "${DB_USERNAME}"
          MYSQL_PASSWORD: "${DB_PASSWORD}"

   phpmyadmin:
      image: phpmyadmin/phpmyadmin
      ports:
          - 8080:80
      networks:
          - database
      depends_on:
          - mysql
      environment:
          PMA_HOST: mysql

volumes:
    data:

networks:
    database:
    server:

.env:

PROJECT_ROOT=./www/html

DB_ROOT_PASSWORD=secret
DB_NAME=project
DB_USERNAME=project
DB_PASSWORD=project

default.conf(nginx配置):

server {
listen 80 default_server;
root /var/www/html;
index index.html index.php;

charset utf-8;

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

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /var/log/nginx/error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_intercept_errors off;
    fastcgi_buffer_size 16k;
    fastcgi_buffers 4 16k;
}

location ~ /\.ht {
    deny all;
}
}

nginx-Dockerfile:

FROM nginx:latest

COPY ./default.conf /etc/nginx/conf.d/default.conf

项目结构:

nginx
  default.conf
  Dockerfile (copies default.conf to nginx configuration location)
php
  Dockerfile (installs extensions)
www
 html
  index.php
.env
docker-compose.yml

我确定问题与文件许可有关,但是我对Docker的了解不足,无法进一步阐述该问题,到目前为止,关于此类问题的其他答案至今仍无济于事,这就是为什么我m在这里发布。

谢谢!

0 个答案:

没有答案