反向代理重定向过多 [英] Too many redirects with reverse proxy

查看:204
本文介绍了反向代理重定向过多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设置:

  • cloudflare DNS
  • docker-compose
  • nginx反向代理
  • wordpress fpm
  • nginx php处理程序

问题

重定向过多,例如在这些日志中:

Too many redirects, like in these logs:

Attaching to wp_db, wp, wp_web
wp_db     | 2020-01-27 12:13:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.11+maria~bionic started.
wp_db     | 2020-01-27 12:13:10+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
wp_db     | 2020-01-27 12:13:10+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 1:10.4.11+maria~bionic started.
wp        | [27-Jan-2020 12:13:10 UTC] PHP Warning:  mysqli::__construct(): (HY000/2002): Connection refused in Standard input code on line 22
wp        | 
wp        | MySQL Connection Error: (2002) Connection refused
wp_db     | 2020-01-27 12:13:11 0 [Note] mysqld (mysqld 10.4.11-MariaDB-1:10.4.11+maria~bionic-log) starting as process 1 ...
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Using Linux native AIO
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Uses event mutexes
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Number of pools: 1
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Using SSE2 crc32 instructions
wp_db     | 2020-01-27 12:13:11 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Completed initialization of buffer pool
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Creating shared tablespace for temporary tables
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: 10.4.11 started; log sequence number 20529037; transaction id 14604
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
wp_db     | 2020-01-27 12:13:11 0 [Note] Plugin 'FEEDBACK' is disabled.
wp_db     | 2020-01-27 12:13:11 0 [Note] Server socket created on IP: '::'.
wp_db     | 2020-01-27 12:13:11 0 [Note] InnoDB: Buffer pool(s) load completed at 200127 12:13:11
wp_db     | 2020-01-27 12:13:11 0 [Warning] 'proxies_priv' entry '@% root@8da7502dc057' ignored in --skip-name-resolve mode.
wp_db     | 2020-01-27 12:13:11 0 [Note] Reading of all Master_info entries succeeded
wp_db     | 2020-01-27 12:13:11 0 [Note] Added new Master_info '' to hash table
wp_db     | 2020-01-27 12:13:11 0 [Note] mysqld: ready for connections.
wp_db     | Version: '10.4.11-MariaDB-1:10.4.11+maria~bionic-log'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
wp        | [27-Jan-2020 12:13:13] NOTICE: fpm is running, pid 1
wp        | [27-Jan-2020 12:13:13] NOTICE: ready to handle connections
wp        | 192.168.48.4 -  27/Jan/2020:12:13:56 +0000 "GET /index.php/wp-admin/install.php"     302
wp_web    | 172.28.0.4 - - [27/Jan/2020:12:13:56 +0000] "GET /index.php/wp-admin/install.php HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0" "MYSERVERIP, 162.158.90.139"
wp        | 192.168.48.4 -  27/Jan/2020:12:13:56 +0000 "GET /index.php/wp-admin/install.php" 302
wp_web    | 172.28.0.4 - - [27/Jan/2020:12:13:56 +0000] "GET /index.php/wp-admin/install.php HTTP/1.1" 302 5 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0" "MYSERVERIP, 162.158.90.139"
// here is the loop

配置:

docker-compose.yml

version: '3'

services:
  wp_db:
    image: mariadb
    container_name: wp_db
    command: --transaction-isolation=READ-COMMITTED --log-bin=mysqld-bin --binlog-format=ROW
    restart: always
    volumes:
      - ./wp_db:/var/lib/mysql
    environment:
      - PUID=33
      - PGID=33
      - MYSQL_PASSWORD=wordpress # needs to be hardcoded
      - MYSQL_DATABASE=wordpress # needs to be hardcoded
      - MYSQL_USER=wordpress # needs to be hardcoded
      - MYSQL_ROOT_PASSWORD=***
    networks:
      - wordpress

  wp:
    image: wordpress:php7.4-fpm-alpine
    container_name: wp
    depends_on:
      - wp_db
    restart: always
    environment:
      - PUID=33
      - PGID=33
      - WORDPRESS_DB_USER=${MYSQL_WORDPRESS_USER}
      - WORDPRESS_DB_PASSWORD=${MYSQL_WORDPRESS_PASSWORD}
      - WORDPRESS_DB_NAME=${MYSQL_WORDPRESS_DB}
      - WORDPRESS_DB_HOST=wp_db
    volumes:
      - ./wordpress-la:/var/www/html:rw
    networks:
      - wordpress

  wp_web:
    build: ./wp_web
    container_name: wp_web
    restart: always
    volumes:
      - ./wordpress-la:/var/www/html
      - ./wp_web/nginx.conf:/etc/nginx/nginx.conf
    environment:
      - PUID=33
      - PGID=33
      - VIRTUAL_HOST=domain.com
      - LETSENCRYPT_HOST=domain.com
    depends_on:
      - wp
    networks:
      - wordpress
      - proxy-tier

networks:
  proxy-tier:

  wordpress:

nginx.conf for wp_web

worker_processes auto;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    keepalive_timeout  65;
    real_ip_header    X-Real-IP;

    upstream php {
        server wp:9000;
    }

    server {
        server_name domain.com;

        root /var/www/html;
        index index.php;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location / {
                try_files $uri $uri/ /index.php?$args;
        }

        location ~ \.php$ {
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
        proxy_redirect off;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }
     }
}

nginx反向代理自动创建其配置,并将请求转发到 wp_web (IIRC).

The nginx reverse proxy creates it's configs automatically and just forwards the requests to wp_web (IIRC).

问题:

如何解决重定向循环?其他一切似乎都起作用.我还可以通过 domain2.com 运行并访问其他容器,而不会出现任何问题.

How to fix the redirect loop? Everything else seems to work. I also have other containers running and accessible via domain2.com without any problems.

预先感谢;)

推荐答案

就像@Damocles所说的,必须有

Like @Damocles stated, there has to be

$ _ SERVER ['HTTPS'] ='on'; wp-config.php 中.标准配置

 if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
     $_SERVER['HTTPS'] = 'on';
 }

似乎还不够.

这篇关于反向代理重定向过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆