首页 > 解决方案 > 上游发送不支持的 FastCGI 协议版本

问题描述

我正在尝试使用 docker-compose 在 nginx 上使用 mysql 设置 wordpress。以下是配置:

nginx:

server {
    server_name blog.site.com;

    index index.php index.html index.htm;

    root /srv/wordpress/data;


    location / {
        root /srv/wordpress/data;
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location /sitemap {
    rewrite ^/sitemap.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    }
    location ~* \.(png|jpg|jpeg|gif|ico)$ {
    expires 1y;
    log_not_found off;
    root /srv/wordpress/data;
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~* \.(css|js|woff2|woff|ttf)$ {
    expires 30d;
    log_not_found off;
    error_log /var/log/nginx/font_err.log;
    root /srv/wordpress/data;
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?q=$uri&$args;
    }
  
    location ~ \.php$ {
        error_log /tmp/php_nginx.log;
        root /srv/wordpress/data;
        try_files $uri $uri/ /index.php?q=$uri&$args;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;

        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

码头工人撰写:


services:
   wpdb:
     image: mysql:5.7
     volumes:
       - /srv/db/wp:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: xxxxxxxxxx
       MYSQL_DATABASE: my_wp
       MYSQL_USER: xxxx
       MYSQL_PASSWORD: xxxxxxxxxx

   wordpress:
     depends_on:
       - wpdb
     image: wordpress:latest
     ports:
       - "9000:9000"
     restart: always
     volumes:
       - ./data:/var/www/html
     environment:
       WORDPRESS_DB_HOST: wpdb://wpdb:3306
       WORDPRESS_DB_USER: xxxx
       WORDPRESS_DB_PASSWORD: xxxxxxxxxx
       WORDPRESS_DB_NAME: my_wp

但我收到此错误:

2020/07/18 09:40:15 [error] 7302#7302: *1 upstream sent unsupported FastCGI protocol version: 72 while reading response header from upstream, client: 213.217.43.162, server: blog.site.com, request: "GET /wp-admin/install.php?step=2 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "blog.site.com"

我看到Drupal 页面返回 502 错误页面而不是 404并且上游发送了不受支持的协议版本和一些其他关于端口的解决方案,但他们无法帮助我解决这个错误

这是我的结果sudo lsof -i :9000

COMMAND    PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
docker-pr 2081 root    4u  IPv6 98062308      0t0  TCP *:9000 (LISTEN)

标签: wordpressdockernginxdocker-compose

解决方案


wordpress:latest我在使用Docker 映像时遇到了同样的错误。更改它wordpress:5.1.1-fpm-alpine为我修复它。

如果您需要进行更多调试,adocker ps -acurl -L localhost:9000是检查 Wordpress 容器是否实际运行正确。这些的输出是什么?

这个 DigitalOcean 教程也完美地为我工作:https ://www.digitalocean.com/community/tutorials/how-to-install-wordpress-with-docker-compose


推荐阅读