[英]How to configure an nginx.conf with a dockerised drupal website?
这是我第一次使用 nginx,我正在使用它从生产子域访问我的 dockerised drupal 应用程序。
所以在一切之前,我目前正在使用 docker-compose 来创建我的 sql、应用程序和 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
我不认为容器是问题,因为当我从 go 到 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;
}
}
这是我的 DockerFile 构建 nginx 图像:
FROM nginx:alpine
COPY nginx.conf /etc/nginx/conf.d/default.conf
当我 go 到 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"
到 go 更详细,我的 docker 文件夹看起来像这样,docroot 包含 drupal 网站。
我已经尝试通过更改端口来解决问题,因为某些解决方案提到了它,但它什么也没做,我不明白可能出了什么问题,我用 conf 尝试了很多东西,但它们都不起作用,我什至仍然可以没有显示 drupal 站点的单页。
drupaldevwithdocker-php 项目没有使用 php-fpm,因此响应不受支持,因为它来自 apache 而不是 php-fpm。 我想你会需要更多这样的东西吗?
proxy_pass http://app:80;
见https://gist.github.com/BretFisher/468bca2900b90a4dddb7fe9a52143fc6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.