nginx错误403-目录索引被禁止
我正在尝试连接nginx错误403-目录索引被禁止,nginx,flask,docker,gunicorn,Nginx,Flask,Docker,Gunicorn,我正在尝试连接docker nginx与docker flask。以下是我的项目结构: . ├── storage │ ├── nginx │ │ └── static │ │ └── image.gif └── web └── flask ├── app │ ├── run.py │ └── templates │ └── index.html ├── con
docker nginx
与docker flask
。以下是我的项目结构:
.
├── storage
│ ├── nginx
│ │ └── static
│ │ └── image.gif
└── web
└── flask
├── app
│ ├── run.py
│ └── templates
│ └── index.html
├── conf
│ ├── nginx-default.conf
│ ├── nginx-flask.conf
│ └── requirements.txt
└── Dockerfile
虽然curl 127.0.0.1:50
和curl 127.0.0.1:80/static/image.gif
工作正常,但当我执行curl 127.0.0.1
时,会出现“403禁止”错误。更具体地说,nginx
给出了以下错误:
2016/03/05 17:54:37 [error] 8#8: *1 directory index of "/usr/share/nginx/html/" is forbidden, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
172.17.0.1 - - [05/Mar/2016:17:54:37 +0000] "GET / HTTP/1.1" 403 169 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0" "-"
我创建如下容器:
docker create \
-v $ROOT/web/flask/app/:/web/flask/app/ \
--name flask_data flask:0.1
docker run \
-d -p 127.0.0.1:50:50 \
--volumes-from flask_data \
--name flask_service flask:0.1
docker create \
-v $ROOT/storage/nginx/:/usr/share/nginx/html/ \
--name nginx_data nginx:1.9
docker run \
-v $ROOT/web/flask/conf/nginx-flask.conf:/etc/nginx/conf.d/nginx-flask.conf \
-v $ROOT/web/flask/conf/nginx-default.conf:/etc/nginx/conf.d/default \
-d -p 127.0.0.1:80:80 \
--volumes-from nginx_data \
--link flask_service:flask_service_alias \
--name nginx_service nginx:1.9
其中,Dockerfile
是:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y --no-install-recommends python-pip python-dev
COPY . /web/flask/
RUN pip install -r /web/flask/conf/requirements.txt
CMD gunicorn run:app --workers=4 --bind=0.0.0.0:50 --log-level=debug --timeout=43200 --chdir=/web/flask/app/
gunicorn==19.4.5
Flask==0.10.1
Flask-Redis==0.1.0
Flask-SQLAlchemy==2.1
Flask-MongoAlchemy==0.7.2
server {
listen 80;
charset utf-8;
location /avatar {
alias /usr/share/nginx/html/avatar;
}
location /scan {
alias /usr/share/nginx/html/scan;
}
location /static {
alias /usr/share/nginx/html/static;
}
location / {
proxy_pass http://flask_service_alias:50/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
而requirements.txt
是:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y --no-install-recommends python-pip python-dev
COPY . /web/flask/
RUN pip install -r /web/flask/conf/requirements.txt
CMD gunicorn run:app --workers=4 --bind=0.0.0.0:50 --log-level=debug --timeout=43200 --chdir=/web/flask/app/
gunicorn==19.4.5
Flask==0.10.1
Flask-Redis==0.1.0
Flask-SQLAlchemy==2.1
Flask-MongoAlchemy==0.7.2
server {
listen 80;
charset utf-8;
location /avatar {
alias /usr/share/nginx/html/avatar;
}
location /scan {
alias /usr/share/nginx/html/scan;
}
location /static {
alias /usr/share/nginx/html/static;
}
location / {
proxy_pass http://flask_service_alias:50/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
nginx default
为空,nginx flask
为:
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y --no-install-recommends python-pip python-dev
COPY . /web/flask/
RUN pip install -r /web/flask/conf/requirements.txt
CMD gunicorn run:app --workers=4 --bind=0.0.0.0:50 --log-level=debug --timeout=43200 --chdir=/web/flask/app/
gunicorn==19.4.5
Flask==0.10.1
Flask-Redis==0.1.0
Flask-SQLAlchemy==2.1
Flask-MongoAlchemy==0.7.2
server {
listen 80;
charset utf-8;
location /avatar {
alias /usr/share/nginx/html/avatar;
}
location /scan {
alias /usr/share/nginx/html/scan;
}
location /static {
alias /usr/share/nginx/html/static;
}
location / {
proxy_pass http://flask_service_alias:50/;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
有什么想法吗?看起来像是
nginx
图像中的default.conf
文件正在接管/
位置。您的nginx run命令具有:
-v $ROOT/web/flask/conf/nginx-default.conf:/etc/nginx/conf.d/default \
这应该覆盖default.conf
,而不仅仅是default
。目前,它只是添加了另一个空白的default
文件,并保留默认的default.conf
,该文件有一个/
的位置
您可以使用静态路由,因为在
nginx flask.conf
到/static
的路径中有一个显式路由,您可以显式调用该文件。您在/
位置上得到了403
,因为索引在默认情况下是禁用的(由autoindex
选项控制)。您是否检查了文件/目录权限?当然。所有文件和(子)目录的权限都设置为drwxrwxr-x
/usr/share/nginx/html/嗯,我指的是主机上的权限(或者说,上面列出的所有权限)。/usr/share/nginx/html/
指的是nginx容器,所以对此一无所知。我想我不应该碰这个,对吗?哦,好吧,你可以试一下,为那些文件夹设置755。哦,亲爱的。现在我明白了。:)你是对的。nginx容器中的/etc/nginx/conf.d/
下有3个文件(不仅仅是两个)!如何启动nginx容器以避免这种行为?非常感谢你!