【问题标题】:nginx: mywebsite.intweb.net redirected you too many times. ERR_TOO_MANY_REDIRECTS,nginx: mywebsite.intweb.net 重定向你太多次。 ERR_TOO_MANY_REDIRECTS,
【发布时间】:2019-05-07 15:10:00
【问题描述】:

当我在浏览器中点击该 URL 时,我不断从 nginx 收到此错误,但我不明白的部分是我的配置中没有任何重写。此外,我在 nginx 的错误日志中也没有得到任何相关信息。我在下面分享我的配置:

# Force HTTP requests to HTTPS
    server {
        listen 80;
        server_name mywebsite.intweb.net;
        return 301 https://mywebsite.intweb.net$request_uri;
    }
      server {

      listen  443 ssl;
      root  /var/opt/httpd/lbdocs;

    server_name mywebsite.intweb.net ;

      # add Strict-Transport-Security to prevent man in the middle attacks
    add_header Strict-Transport-Security "max-age=31536000" always;
    ssl_certificate     /etc/pki/tls/certs/star_intweb_net.pem;
    ssl_certificate_key /etc/pki/tls/certs/star_intweb_net.key;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;

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

   # include rewrites/mywebsite.com.conf;


    index  index.php index.html index.htm;

    # Make nginx serve static files instead of Apache
    # NOTE this will cause issues with bandwidth accounting as files wont be logged
    location ~* \.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|htm|html|js|css)$ {
        expires max;
    }

    location / {
        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;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8080;
         }

    # proxy the PHP scripts to Apache listening on <serverIP>:8080
    location ~ \.php$ {
        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;
        proxy_set_header Host $host;
        proxy_pass http://127.0.0.1:8080;
         }

    location ~ /\. {
        deny  all;
    }

谢谢

【问题讨论】:

  • 这是一个 WordPress 网站吗?
  • 127.0.0.1:8080 是您的后端服务器吗?
  • @IvanShatsky 是的
  • @Light.G 是的,我在后端运行了 apache,但是当我向后端发送 ssl 请求时没有发生这种情况,直到我将其更改为纯 HTTP,如您所见与127.0.0.1:8080
  • 作为一种快速解决方法,在您当前主题的functions.php 文件的开头添加remove_action('template_redirect', 'redirect_canonical');

标签: wordpress nginx nginx-config


【解决方案1】:

问题与 WordPress 有关。我必须根据我的 nginx 配置指向的内容将 wordpress wp-config.php 文件编辑为 https 或常规 http,否则 nginx 和 wordpress 会不断相互重定向,然后会发生此错误。

【讨论】:

    【解决方案2】:

    这个website 能够解决我的问题:

    我们反复遇到的最常见的错误配置是用户在 WordPress 地址 URL 或站点地址 URL 设置中的 URL 不正确。

    例如,假设您网站的网址是 http://www.example.com,然后您转到设置 » 常规并将其设置为 http://example.com。大多数网络主机允许您选择是否要为您的域名添加 www 前缀或不使用 www。如果您选择将 www 添加到您的 URL,那么在您的 WordPress 设置中添加 http://example.com 将导致错误。或者,如果您选择使用不带 www 前缀的域,则在 WordPress 设置中添加带有 www 前缀的域会导致此错误。

    如果这仍然不能解决问题,您将不得不在 WP 正在使用的数据库中进行搜索和替换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-21
      • 1970-01-01
      • 1970-01-01
      • 2020-08-22
      • 2020-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多