简体   繁体   中英

nginx error 403 - directory index is forbidden

I am trying to connect docker nginx with docker flask . Here is the structure of my project:

.
├── storage
│   ├── nginx
│   │   └── static
│   │       └── image.gif
└── web
    └── flask
        ├── app
        │   ├── run.py
        │   └── templates
        │       └── index.html
        ├── conf
        │   ├── nginx-default.conf
        │   ├── nginx-flask.conf
        │   └── requirements.txt
        └── Dockerfile

Although curl 127.0.0.1:50 and curl 127.0.0.1:80/static/image.gif work fine, I get a '403 Forbidden' error when I do curl 127.0.0.1 . More specifically, nginx gives the following error:

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" "-"

I create the containers like this:

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

where, Dockerfile is:

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/

and requirements.txt is:

gunicorn==19.4.5
Flask==0.10.1
Flask-Redis==0.1.0
Flask-SQLAlchemy==2.1
Flask-MongoAlchemy==0.7.2

nginx-default is empty, and nginx-flask is:

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;
    }

}

any ideas?

It looks like what might be going on is the default.conf file in the nginx image is taking over the / location. You nginx run command has:

-v $ROOT/web/flask/conf/nginx-default.conf:/etc/nginx/conf.d/default \

This should be overwriting the default.conf instead of just default . As it currently stands, it just adds another blank default file and leaves the default default.conf which has a location for / .

You static route does work because there is an explicit route in the nginx-flask.conf to /static and you call the file explicitly. You get a 403 on the / location because indexes are disabled by default (controlled by the autoindex option).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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