programing

Docker에서 Wordpress로 게시물을 저장할 수 없습니다.

linuxpc 2023. 6. 30. 22:09
반응형

Docker에서 Wordpress로 게시물을 저장할 수 없습니다.

저는 도커에서 워드프레스를 실행하고 있습니다. 다음과 같이 구성합니다.docker-compose.yml:

version: '2'

services:
  db_wordpress:
    image: mysql:5.7
    volumes:
      - db_wordpress_data:/var/lib/mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: pwd
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: pwd

  wordpress:
    image: wordpress:latest
    volumes:
      - ./wp-content:/var/www/html/wp-content
    restart: unless-stopped
    expose:
      - 80
    depends_on:
      - db_wordpress
    environment:
      WORDPRESS_DB_HOST: db_wordpress:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: pwd
      WORDPRESS_DEBUG: 1
      WORDPRESS_CONFIG_EXTRA: |
        // Enable Debug logging to the /wp-content/debug.log file
        define('WP_DEBUG_LOG', true);
        // Disable display of errors and warnings
        define('WP_DEBUG_DISPLAY', false);
        // Handle subpath /blog
        define('WP_HOME','https://www.example.com/blog');
        define('WP_SITEURL','https://www.example.com/blog');
        $$_SERVER['REQUEST_URI'] = '/blog' . $$_SERVER['REQUEST_URI'];

  nginx:
    image: nginx
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    links:
      - wordpress
    volumes:
      - /var/www/letsencrypt:/var/www/letsencrypt
      - ./logs/nginx:/var/log/nginx
      - ./nginx.conf:/etc/nginx/nginx.conf

volumes:
    db_wordpress_data:

그래서 언론 사이트라는 단어는 뒤에 있습니다.nginx다음이 포함된 용기nginx.conf파일:

events {
    worker_connections 1024;
}

http {
  upstream wordpress {
    server wordpress:80;
  }

  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  sendfile on;
  keepalive_timeout 65;

  server_names_hash_bucket_size 512;

  proxy_cache_path /var/cache levels=1:2 keys_zone=STATIC:10m inactive=24h  max_size=1g;

  server {
    listen 80;
    server_name example.com;

    location / {
      return 301 https://$host$request_uri;
    }
  }

  server {
    listen 443 default_server ssl;

    server_name example.com;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    try_files   $uri $uri/ =404;

    location /blog/ {
      proxy_pass http://wordpress/;
      proxy_buffering off;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
    }
  }
}

이제 내 워드프레스 관리자, 플러그인 설치 등에 액세스할 수 있지만 게시물이나 페이지를 업데이트하고 싶을 때500브라우저에서 오류가 발생하고 로그)docker logs -f clearroad_wordpress_1):

[Thu Jan 03 17:03:36.105145 2019] [core:error] [pid 97] [client 172.18.0.5:51210] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: https://www.example.com/blog/wp-admin/post.php?post=62&action=edit
172.18.0.5 - - [03/Jan/2019:17:03:36 +0000] "POST /wp-json/wp/v2/posts/62/autosaves?_locale=user HTTP/1.0" 500 806 "https://www.example.com/blog/wp-admin/post.php?post=62&action=edit" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko)

그래서 그 요청들은/blog/wp-json리다이렉트 루프에 빠집니다. 원인은 무엇입니까?

확인했습니다..htaccess워드프레스 컨테이너에 있는 파일:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress

.htaccessNginx를 사용하고 있기 때문에 워드프레스 설치에 영향을 미치지 않아야 합니다.

Nginx 인스턴스를 올바르게 구성하려면 다음 게시물을 참조하십시오.HTTPS 사용 여부, 캐시 플러그인 등에 따라 몇 가지 레시피가 있습니다.

Wordpress 컨테이너에서 http로 프록시를 사용하지만 Wordpress가 https에서 작동하도록 구성했기 때문에 리디렉션 루프가 발생하고 있습니다.

구성을 위해 wp-config에 다음을 추가하십시오.그것을 해결하기 위해 행복한 블로그 줄 앞에 php:

    if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false) {
        $_SERVER['HTTPS'] = 'on';
    }
/* That's all, stop editing! Happy blogging. */

언급URL : https://stackoverflow.com/questions/54027796/can-not-save-post-with-wordpress-on-docker

반응형