wordpress 在 docker 容器中运行并使用 nginx 作为反向代理时出现的问题

wordpress 在 docker 容器中运行并使用 nginx 作为反向代理时出现的问题

我已经使用官方wordpressmysql图像将现有的 Wordpress 博客移动到 docker,如下所示:

version: "3.9"

services:
  db:
    image: mysql:5.7
    volumes:
      - ./db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: somewordpress
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress

  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    volumes:
      - ./wordpress_data:/var/www/html
    ports:
      - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
      WORDPRESS_DB_NAME: wordpress
      WORDPRESS_DEBUG: 1
volumes:
  db_data: {}
  wordpress_data: {}

该服务器nginx作为反向代理运行,执行 HTTPS 协议终止并将流量重定向到localhost端口上的 docker 容器8000

  location /blog {
      proxy_pass http://localhost:8000;

      # Do not buffer responses from proxied server
      proxy_buffering off;

      # The HTTP protocol for proxying (1.0 by default). Needs to be 1.1 for websockets and keepalive
      proxy_http_version 1.1;

      proxy_set_header Host            $host;

      # Forward the real visitor remote IP address to the proxied server
      proxy_set_header X-Real-IP       $remote_addr;

      # A list containing the IP addresses of every server the client has been proxied through
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      # When used inside an HTTPS server block, each HTTP response from the proxied server is rewritten to HTTPS.
      proxy_set_header X-Forwarded-Proto $scheme;

      # The original port requested by the client
      proxy_set_header X-Forwarded-Port 443;

      # Defines the original host requested by the client.
      proxy_set_header X-Forwarded-Host  $host;
  }

当尝试从 Web 浏览器访问博客时,唯一加载的资源是 index.php。所有其他资源(如css图像文件)均返回404

在此处输入图片描述

这可能是什么原因呢?

编辑1/var/www/html:从容器中列出的结果wordpress

geschema@electrolite-22:~/docker/blog$ docker container exec -it ad276615ba09 bash
root@ad276615ba09:/var/www/html# ls -al
total 244
drwxr-xr-x  5 www-data www-data  4096 Jul 16 10:03 .
drwxr-xr-x  1 root     root      4096 Jun 23 07:22 ..
-rw-r--r--  1 www-data www-data   261 Jun 24 01:57 .htaccess
-rw-r--r--  1 www-data www-data   405 Feb  6  2020 index.php
-rw-r--r--  1 www-data www-data 19915 Jan  1  2022 license.txt
-rw-r--r--  1 www-data www-data  7401 Mar 22 21:11 readme.html
-rw-r--r--  1 www-data www-data  7165 Jan 21  2021 wp-activate.php
drwxr-xr-x  9 www-data www-data  4096 May 24 19:02 wp-admin
-rw-r--r--  1 www-data www-data   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 www-data www-data  2338 Nov  9  2021 wp-comments-post.php
-rw-rw-r--  1 www-data www-data  5480 Jun 24 01:56 wp-config-docker.php
-rw-r--r--  1 www-data www-data  3001 Dec 14  2021 wp-config-sample.php
-rw-r--r--  1 www-data www-data  5584 Jun 28 18:00 wp-config.php
drwxr-xr-x  6 www-data www-data  4096 Jul 16 11:42 wp-content
-rw-r--r--  1 www-data www-data  3943 Apr 28 09:49 wp-cron.php
drwxr-xr-x 26 www-data www-data 16384 May 24 19:02 wp-includes
-rw-r--r--  1 www-data www-data  2494 Mar 19 20:31 wp-links-opml.php
-rw-r--r--  1 www-data www-data  3973 Apr 12 01:47 wp-load.php
-rw-r--r--  1 www-data www-data 48498 Apr 29 14:36 wp-login.php
-rw-r--r--  1 www-data www-data  8577 Mar 22 16:25 wp-mail.php
-rw-r--r--  1 www-data www-data 23706 Apr 12 09:26 wp-settings.php
-rw-r--r--  1 www-data www-data 32051 Apr 11 11:42 wp-signup.php
-rw-r--r--  1 www-data www-data  4748 Apr 11 11:42 wp-trackback.php
-rw-r--r--  1 www-data www-data  3236 Jun  8  2020 xmlrpc.php

编辑2:摘自wordpress容器日志,我们可以看到仅/blog返回状态代码200

90.19.131.1 - - [16/Jul/2022:13:33:28 +0000] "GET /blog/ HTTP/1.1" 200 17386 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
90.19.131.1 - - [16/Jul/2022:13:33:28 +0000] "GET /blog/wp-includes/js/jquery/jquery-migrate.min.js?ver=3.3.2 HTTP/1.1" 404 35182 "https://example.com/blog/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
90.19.131.1 - - [16/Jul/2022:13:33:28 +0000] "GET /blog/wp-content/themes/twentyfifteen/genericons/genericons.css?ver=20201208 HTTP/1.1" 404 35182 "https://example.com/blog/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"
90.19.131.1 - - [16/Jul/2022:13:33:28 +0000] "GET /blog/wp-content/themes/twentyfifteen/css/blocks.css?ver=20190102 HTTP/1.1" 404 35182 "https://example.com/blog/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36"

相关内容