简体   繁体   English

403 禁止访问 - Nginx、Docker & Windows

[英]403 Forbidden - Nginx, Docker & Windows

I'm currently trying to setup a local dev machine with docker, using nginx. I recently switched from Virtualbox support to Hyper-v, and since then I get a 403 Forbbiden in Nginx.我目前正在尝试使用 docker 设置本地开发机器,使用 nginx。我最近从 Virtualbox 支持切换到 Hyper-v,从那时起我在 Nginx 中获得了 403 Forbbiden。

I'm following this tutorial to set up things http://tech.osteel.me/posts/2015/12/18/from-vagrant-to-docker-how-to-use-docker-for-local-web-development.html我正在按照本教程进行设置http://tech.osteel.me/posts/2015/12/18/from-vagrant-to-docker-how-to-use-docker-for-local-web-发展.html

My Nginx config is as follows我的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;
    }
}

And my docker-compose还有我的 docker-compose

nginx:
    build: ./nginx/
    ports:
        - 80:80
    links:
        - php
    volumes_from:
        - app

php:
    build: ./php/
    expose:
        - 9000
    links:
        - mysql
    volumes_from:
        - app

app:
    image: php:7.0-fpm
    volumes:
        - ~/docker:/var/www/html
        #also tried .:/var/www/html
        #and ./docker:/var/www/html
    command: "true"

mysql:
    image: mysql:latest
    volumes_from:
        - data
    environment:
        MYSQL_ROOT_PASSWORD: secret
        MYSQL_DATABASE: project
        MYSQL_USER: project
        MYSQL_PASSWORD: project

data:
    image: mysql:latest
    volumes:
        - /var/lib/mysql
    command: "true"

phpmyadmin:
    image: phpmyadmin/phpmyadmin
    ports:
        - 8080:80
    links:
        - mysql
    environment:
        PMA_HOST: mysql

Docker folder is inside my C:/User/docker Docker 文件夹在我的 C:/User/docker

What's the catchup here?这里有什么要注意的? Thanks谢谢

Verify that index.html or index.php exists in your C:/User/docker folder as if that doesn't exist, you will see 403 forbidden as by default you cannot browse the directory.验证index.htmlindex.php存在于您的C:/User/docker文件夹中,就好像它不存在一样,您将看到 403 forbidden,因为默认情况下您无法浏览该目录。

Then try the following in your docker-compose:然后在您的 docker-compose 中尝试以下操作:

volumes:
    - /C/User/docker:/var/www/html

Hope it helps.希望能帮助到你。

A stable dockerfile and image is available on the port of Docker's open source to Windows by WinDocks. WinDocks在Windows的Docker开源端口上提供了稳定的dockerfile和映像。 WinDocks runs on all editions of Windows 8, 10, Server 2012 and 2016. The 1.04 release includes support for Tomcat, Jetty, Nginx, and Node.js. WinDocks可在Windows 8、10,Server 2012和2016的所有版本上运行。1.04版本包含对Tomcat,Jetty,Nginx和Node.js的支持。 Free Community edition is Here 免费社区版在这里

Disclosure: I am the Co-Founder of WinDocks 披露:我是WinDocks的联合创始人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM