我有以下Nginx配置和docker-compose.yaml。在我添加以下块之前,
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /etc/nginx/conf.d/privkey.pem;
ssl_certificate_key /etc/nginx/conf.d/mynginx.key;
location / {
proxy_pass http://web/;
}
}
通过HTTP的一切工作正常。添加上面的代码块后,一切都停止了,我无法通过HTTP / HTTPS访问该站点。
docker-compose logs nginx output
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
mynginx.conf
upstream web {
ip_hash;
server web:8000;
}
# portal
server {
location / {
proxy_pass http://web/;
}
listen 8000;
server_name localhost;
}
# portal (https)
server {
listen 443;
server_name localhost;
ssl on;
ssl_certificate /etc/nginx/conf.d/privkey.pem;
ssl_certificate_key /etc/nginx/conf.d/mynginx.key;
location / {
proxy_pass http://web/;
}
}
搬运工-compose.yaml
ubuntu@ip-172-31-9-162:~/django_docker$ cat docker-compose.yml
version: '2'
services:
nginx:
image: nginx:latest
container_name: ng01
ports:
- "80:8000"
- "443:443"
volumes:
- ./src:/src
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
container_name: dg01
command: bash -c "python manage.py makemigrations && python manage.py migrate && gunicorn composeexample.wsgi -b 0.0.0.0:8000"
depends_on:
- db
volumes:
- ./src:/src
expose:
- "8000"
db:
image: postgres:latest
container_name: ps01
文件夹结构
.
├── config
│ ├── nginx
│ │ ├── mynginx.conf
│ │ ├── mynginx.conf~
│ │ ├── mynginx.crt
│ │ ├── mynginx.key
│ │ └── privkey.pem
│ └── requirements.pip
├── docker-compose.yml
├── docker-compose.yml~
├── Dockerfile
└── src
├── composeexample
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-35.pyc
│ │ ├── __init__.cpython-36.pyc
│ │ ├── settings.cpython-35.pyc
│ │ ├── settings.cpython-36.pyc
│ │ ├── urls.cpython-35.pyc
│ │ ├── urls.cpython-36.pyc
│ │ ├── wsgi.cpython-35.pyc
│ │ └── wsgi.cpython-36.pyc
│ ├── settings.py
│ ├── settings.py~
│ ├── urls.py
│ └── wsgi.py
├── db.sqlite3
└── manage.py