简体   繁体   English

Ubuntu Nginx容器403禁止

[英]Ubuntu nginx container 403 forbidden

I've build an ubuntu container with nginx websever. 我已经用nginx websever构建了一个ubuntu容器。 The docker file looks as follow: docker文件如下所示:

FROM ubuntu:14.04
MAINTAINER James Turnbull "james@example.com"
ENV REFRESHED_AT 2014-06-01
RUN apt-get -yqq update && apt-get -yqq install nginx
RUN mkdir -p /var/www/html/website
ADD nginx/global.conf /etc/nginx/conf.d/
ADD nginx/nginx.conf /etc/nginx/nginx.conf
EXPOSE 80

The file structure looks as follow: 文件结构如下:

xxxxxx@xxxxx:~/sample$ ls
Dockerfile  nginx  website

After running the container with the statement: 使用以下语句运行容器后:

sudo docker run -d -p 80 --name website \-v $PWD\website:/var/www/html/website \kostonstyle/nginx nginx

The nginx server works as expected but when I request for a webpage, I've got only Nginx服务器工作正常,但是当我请求一个网页时,我只有

curl 0.0.0.0:32769
<html>
  <head><title>403 Forbidden</title></head>
  <body bgcolor="white">
    <center><h1>403 Forbidden</h1></center>
    <hr><center>nginx/1.4.6 (Ubuntu)</center>
  </body>
</html>

What am I doing wrong? 我究竟做错了什么?

The 403 error can be the result of serving an empty directory, and directory-listing disabled (the default). 403错误可能是由于提供了一个空目录而禁用了目录列表(默认)的结果。 See resolving 403 errors for some hints on how to resolve this. 有关解决此问题的一些提示,请参见解决403错误

If the website directory does not contain an index.html , add this file 如果网站目录不包含index.html ,请添加此文件

If the website directory does contain an index.html , it's possible that the volume is not mounted correctly. 如果网站目录中确实包含index.html ,则可能是卷未正确安装。 If you're using boot2docker, make sure that your website directory is underneath the c:\\users (Windows) or /Users (OS X) directory, because only those directories are accessible by docker (by default) 如果您使用的是boot2docker,请确保您的网站目录位于c:\\users (Windows)或/Users (OS X)目录下,因为docker只能访问这些目录(默认情况下)

As an additional comment to thaJeztah's answer, note that the mapping on Windows is case sensitive, so if you wish to map to a 'Sites' folder under your 'c:\\users' dir then you'll need to specify the mapping with the right casing: 作为thaJeztah回答的补充说明,请注意Windows上的映射区分大小写,因此,如果要映射到'c:\\ users'目录下的'Sites'文件夹,则需要使用右外壳:

docker run --name website -p 80 -d -v /c/Users/username/Sites:/var/www/html/website nginx

(I would post as a comment on thaJeztah's answer but I don't have enough rep yet!) (我会发表评论,对thaJeztah的回答,但我没有足够的代表!)

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

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