【发布时间】:2021-03-11 09:03:35
【问题描述】:
这是我第一次使用 nginx,我正在使用它从生产子域访问我的 dockerised drupal 应用程序。
所以在一切之前,我目前正在使用 docker-compose 来创建我的 sql、app 和 web 服务容器,这是我的 docker-compose 文件:
version: '3'
services:
app:
image: osiolabs/drupaldevwithdocker-php:7.4
volumes:
- ./docroot:/var/www/html:cached
depends_on:
- db
restart: always
container_name: intranet
db:
image: mysql:5.5
volumes:
- ./mysql:/var/lib/mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=linux1354web
- MYSQL_USER=root
- MYSQL_PASSWORD=linux1354web
- MYSQL_DATABASE=intranet
container_name: intranet-db
web:
build: ./web
ports:
- 88:80
depends_on:
- app
volumes:
- ./docroot:/var/www/html:cached
restart: always
container_name: webIntranet
我认为容器不是问题,因为当我访问 drupal 容器时,该站点可以正常工作,但我的主要问题是与 nginx 容器的链接。这是我的 nginx.conf :
# stuff for http block
client_max_body_size 1g;
# fix error: upstream sent too big header while reading response header from upstream
fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k;
server {
listen 80;
listen [::]:80 default_server;
server_name _;
index index.php index.html;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www/html;
#RENVOYER LA PAGE DE GARDE DE APACHE2
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php?$query_string; # For Drupal >= 7
}
location /intranet {
# try to serve file directly, fallback to app.php
try_files $uri $uri/;
}
#RENVOYER LE FICHIER ROBOTS.TXT
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location ~ \.php(/|$) {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass app:80;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $document_root;
}
}
这是我构建 nginx 镜像的 DockerFile:
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
当我转到 localhost:88/ 时,我目前有一个 apache2 集线器页面,但是当我尝试另一个页面时,我总是收到 502 bad gateway 错误,并且日志显示:
webIntranet | 2021/03/11 08:44:55 [error] 30#30: *1 upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream, client: 172.26.0.1, server: _, request: "GET /index HTTP/1.1", upstream: "fastcgi://172.26.0.3:80", host: "localhost:88"
更详细地说,我的 docker 文件夹看起来像这样,docroot 包含 drupal 网站。
我尝试通过更改端口来解决问题,因为某些解决方案提到了它,但它什么也没做,我不明白可能出了什么问题,我用 conf 尝试了很多东西,但它们都不起作用,而且我仍然无法显示 drupal 站点的单个页面。
【问题讨论】: