我有jwilder提供的nginx-proxy以及随附的letsencrypt容器在服务器上运行。我现在正在尝试将各种小项目(例如laravel应用程序)添加到整个过程中。尝试尝试,我似乎无法使所有容器都运行。首先是我的docker-compose.yml
version: '2'
services:
web:
build:
context: ./
dockerfile: web.docker
volumes:
- ./:/var/www
expose:
- "80"
environment:
- VIRTUAL_HOST=mywebsite.com
- VIRTUAL_PORT=80
- LETSENCRYPT_HOST=mywebsite.com
- LETSENCRYPT_EMAIL=me@mywebsite.com
links:
- app
networks:
- nginx-proxy
depends_on:
- app
app:
build:
context: ./
dockerfile: app.docker
volumes:
- ./:/var/www
links:
- db
environment:
- DB_PORT=3306
- DB_HOST=db
db:
image: mysql:5.7
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_DATABASE=dockerApp
ports:
- "33061:3306"
networks:
nginx-proxy:
external: true
然后是我的web.docker
FROM nginx:1.10
ADD vhost.conf /etc/nginx/conf.d/default.conf
最后是我的vhost.conf
server {
listen 80;
listen 443;
root /var/www/public;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
index index.php index.htm index.html;
client_max_body_size 0;
location / {
# try to serve file directly, fallback to index.php
proxy_pass https://mywebsite.com;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ ^/.+\.php(/|$) {
fastcgi_pass app:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
我尝试将我的fastcgi_pass更改为生成的容器名称,我尝试完全放弃proxy_pass并将其更改为app:9000
。我尝试在docker-compose.yml
中使用volumes_from,有无links
等。无论我尝试什么,都会出现相同的错误:
2018/07/16 11:50:52 [emerg] 1#1: host not found in upstream "app" in /etc/nginx/conf.d/default.conf:21
nginx: [emerg] host not found in upstream "app" in /etc/nginx/conf.d/default.conf:21
将app
更改为Docker容器的名称无效。在我看来,nginx服务器找不到应用程序容器,但我不知道问题出在哪里。运行app
时,我的db
和docker container ls
容器正在运行。该应用容器的最新日志条目是
[16-Jul-2018 11:40:19] NOTICE: fpm is running, pid 1
[16-Jul-2018 11:40:19] NOTICE: ready to handle connections