【问题标题】:Nginx as reverse proxy for Apache (RHEL 8), http to https rewrites, ERR_TOO_MANY_REDIRECTSNginx 作为 Apache (RHEL 8) 的反向代理,http 到 https 重写,ERR_TOO_MANY_REDIRECTS
【发布时间】:2020-05-19 17:07:30
【问题描述】:

我一直在尝试使用 Nginx 作为 Apache 的反向代理进行设置,但无济于事,我的大脑开始融化。我正在运行一个 CentOS 8 系统,Apache 配置为仅侦听端口 8080。我有一个 Apache 虚拟主机配置如下:

<VirtualHost *:8080>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /home/user/public_html/example.com

    <Directory /home/user/public_html/example.com>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>

    ErrorLog /var/log/httpd/example.com-error.log
    CustomLog /var/log/httpd/example.com.log combined
</VirtualHost>

Nginx 充当反向代理并侦听 HTTP 和 HTTPS 连接并代理与 Apache 的连接。 domain.com 包含一个 PHP 应用程序 (Laravel)。我有以下 Nginx 的服务器配置:

server {
  listen 80 default_server;
  listen [::]:80 default_server;
  server_name example.com www.example.com;
  return 301 https://example.com$request_uri;
}

server {
  listen 443 ssl default_server;
  listen [::]:443 ssl default_server;
  server_name example.com www.example.com;
  root /home/user/public_html/example.com;
  index index.php index.html index.htm;
  ssl on;
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_session_cache shared:SSL:20m;
  ssl_session_timeout 60m;
  ssl_prefer_server_ciphers on;
  add_header Strict-Transport-Security max-age=16000000;

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

  location ~ \.php$ {
    proxy_set_header X-Real-IP  $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:8080;
    #proxy_redirect off;
  }

  location ~ /\.ht {
    deny all;
  }
}

非常感谢任何帮助。我无法加载应用程序,所有请求都返回 ERR_TOO_MANY_REDIRECTS。

【问题讨论】:

    标签: apache http nginx https nginx-reverse-proxy


    【解决方案1】:

    Apache 的 Nginx 代理

    server {
           listen 443 ssl;
           server_name www.example.com example.com;
    
           ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
           ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
           ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
           ssl_ciphers         HIGH:!aNULL:!MD5;
    
            location / {
                proxy_pass http://127.0.0.1:8080;
                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 https;
                proxy_set_header X-Forwarded-Port 443;
                proxy_set_header Host $host;
            }
            location /.git {
                deny all;
                return 404;
            }
    }
    

    还要检查 htaccess 是否有重定向块。

    【讨论】:

      猜你喜欢
      • 2017-07-10
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 1970-01-01
      • 2011-06-08
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多