我正在尝试通过Docker配置访问我现有的Wordpress实例。
我的计划是在我的VPS上运行一些网站,因此我想进行此Docker设置。首先,我的jwilder/nginx-proxy
文件:
version: '3'
services:
nginx:
image: jwilder/nginx-proxy
container_name: nginx
restart: always
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: 'true'
ports:
- 80:80
- 443:443
volumes:
- /srv/nginx/data/certs:/etc/nginx/certs:ro
- /srv/nginx/data/conf.d:/etc/nginx/conf.d
- /srv/nginx/data/vhost.d:/etc/nginx/vhost.d
- /srv/nginx/data/html:/usr/share/nginx/html
- /var/run/docker.sock:/tmp/docker.sock:ro
letsencrypt:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: letsencrypt
volumes:
- /srv/nginx/data/vhost.d:/etc/nginx/vhost.d
- /srv/nginx/data/certs:/etc/nginx/certs:rw
- /srv/nginx/data/html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
depends_on:
- nginx
networks:
default:
external:
name: nginxproxy_default
我使用sudo docker-compose up
运行它,效果很好。
然后,我有另一个文件用于我的一个Wordpress项目:
version: '3'
services:
wp:
image: wordpress:php7.3-fpm
container_name: wp_my_project
expose:
- 3001
volumes:
- ./conf/php/conf.d/php.ini:/etc/php/7.3/fpm/php.ini
- ./conf/php/pool.d/www.conf:/etc/php/7.3/fpm/pool.d/www.conf
environment:
- WORDPRESS_DB_NAME=my_project
- WORDPRESS_TABLE_PREFIX=wp_
- WORDPRESS_DB_HOST=mysql_my_project
- WORDPRESS_DB_USER=my_project_user
- WORDPRESS_DB_PASSWORD=my_project_password
- VIRTUAL_HOST=test.local
- VIRTUAL_PORT=3001
- LETSENCRYPT_HOST=test.local
- LETSENCRYPT_EMAIL=my_project@gmail.com
depends_on:
- db
restart: always
db:
image: mysql:8.0
container_name: mysql_my_project
command: --default-authentication-plugin=mysql_native_password
volumes:
- ./mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=whatever
- MYSQL_USER=root
- MYSQL_PASSWORD=whatever_again
- MYSQL_DATABASE=my_project
restart: always
networks:
default:
external:
name: nginxproxy_default
在运行它们之前,我先创建网络:
docker network create nginxproxy_default
我已经尝试了好几天没有成功。
如果我使用以下命令进入nginx
码头工人集装箱,则
docker exec -it nginx bash
我可以在文件/etc/nginx/conf.d
中看到它:
...
# test.local
upstream test.local {
## Can be connected with "nginx-proxy_proxy" network
# wp_my_project
server 172.19.0.5:3001;
}
server {
server_name test.local;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
include /etc/nginx/vhost.d/default;
location / {
proxy_pass http://test.local;
}
}
server {
server_name test.local;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
return 500;
ssl_certificate /etc/nginx/certs/default.crt;
ssl_certificate_key /etc/nginx/certs/default.key;
}
...
看起来还可以,但是当我尝试导航到 http://test.local 时,只会得到一个 502错误。
作为最后的信息,我将在此处提供以下结果:
docker network inspect nginxproxy_default
[
{
"Name": "nginxproxy_default",
"Id": "aa332a0666fcf91af535134bb699caeef0eaf03136cc2582c21765fe03b8da31",
"Created": "2019-06-19T20:28:53.590261887+02:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.22.0.0/16",
"Gateway": "172.22.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"3567b10ef6c755ba733571a69a2b14ccc2e10d0a3288346f874cccb23ce9e4fa": {
"Name": "wp_my_project",
"EndpointID": "7e7fe30107887b0a2a83c60ac15896eab144294defa6df5ff0a5b0ee2debf40f",
"MacAddress": "02:42:ac:16:00:03",
"IPv4Address": "172.22.0.3/16",
"IPv6Address": ""
},
"68a2608c34196bd2e9da20b4edc4d6c7851f27dcd3cf9db03ed2850e3ce4296e": {
"Name": "nginx",
"EndpointID": "ce124164464350d736afc94095242914bb7f8b7b59c4884b06c972612a6b8f0e",
"MacAddress": "02:42:ac:16:00:04",
"IPv4Address": "172.22.0.4/16",
"IPv6Address": ""
},
"6a87fad4472a37702647b82885ad715acad21701ef992870a2f2cc3490df8a7c": {
"Name": "mysql_my_project",
"EndpointID": "71dce4bc75f496e908e4a16e948328fadfa5c4982aeb2898b98f868691465257",
"MacAddress": "02:42:ac:16:00:02",
"IPv4Address": "172.22.0.2/16",
"IPv6Address": ""
},
"7518524e7bda2c41664cc46bd4c1d18bf5af09e1d5d2a66557eb49bfc6bff95f": {
"Name": "letsencrypt",
"EndpointID": "a15cb4d825cd53acad64cda5070eadc8f97bc5cab1ee45974f967c7da131c2e4",
"MacAddress": "02:42:ac:16:00:05",
"IPv4Address": "172.22.0.5/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {}
}
]
答案 0 :(得分:0)
您的容器不在同一网络上,因此它们不会互相看到。首先,您应该将它们全部放在同一网络nginx-proxy_proxy
上。我猜您正在使用它,因为docker-compose创建了它。您可以使用docker network create some-name
创建自己的文件并使用它。这样,您就不必依赖docker-compose命名网络的方式(它也依赖于父文件夹,因此,如果进行此更改,您会遇到麻烦)。
执行此操作后,应将server 172.19.0.5:3001;
更改为server wp:3001
。请勿使用IP地址,因为这是一种更改。如果图像的Dockerfile中尚未声明expose: 3001
,则也只需要声明。
关于第一个docker-compose的另一条说明:您无需将容器连接到网桥网络即可访问它们-您已经通过端口映射完成了此操作。
答案 1 :(得分:0)
在使用php-fpm时,我的 wp 服务缺少此环境变量:
VIRTUAL_PROTO: fastcgi
之后,我可以设法提供这种php版本所需的一些特殊配置。
像这样...
但是,我仍然遇到问题,因为到达的网站就像一个新的网站(当我使用卷提供现有的网站时,我可以在容器内正确看到它)以及所有静态文件没有经过。