Apache proxypass 未检索预期内容

Apache proxypass 未检索预期内容

一直试图设置一个 Apache 代理,以便从新的应用服务器为子目录中的所有内容提供服务

如果我使用此重写规则,它就会起作用,并且我会被重定向到新网站

RewriteRule ^/blog/(.+)/$ "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog/$1" [R,L]

因此我尝试将其更改为代理指令:

RewriteRule ^/blog/(.+)/$ "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog/$1" [P,L]
ProxyPassReverse "/blog/" "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog/"

没有用。
决定尝试将其设置为位置块中的代理密码:

<Location "/blog/">
  SSLProxyEngine on
  ProxyPreserveHost on
  ProxyPass "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog/"
  ProxyPassReverse  "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog/"
</Location>

还是没用

从位置块中取出指令并将其编辑为:

  SSLProxyEngine on
  ProxyPreserveHost on
  ProxyPass "/blog/" "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog"
  ProxyPassReverse "/blog/" "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog"

还是行不通

关闭证书验证(我信任新应用服务器上的证书):

SSLProxyVerify none 
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
SSLProxyCheckPeerExpire off

因此,最终请求被传递到另一台服务器,但现在我看到应用程序服务器返回了 404 错误,因为该服务器无法理解原始 URL(https://www.mysite.co.uk/blog/

两个服务器的日志文件中都没有错误?!?!

我需要做哪些改变才能使其正常工作?

apachectl -S 的输出:

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server indigo-1.mysite.co.uk (/etc/httpd/conf.d/000-mysite.conf:27)
         port 80 namevhost indigo-1.mysite.co.uk (/etc/httpd/conf.d/000-mysite.conf:27)
         port 80 namevhost www.mysite.co.uk (/etc/httpd/conf.d/zzz-mysite.conf:59)
                 alias mysite.co.uk
                 alias cdn.mysite.co.uk
         port 80 namevhost pugpig.mysite.co.uk (/etc/httpd/conf.d/zzz-mysite.conf:73)
         port 80 namevhost www.mysite2.co.uk (/etc/httpd/conf.d/zzz-mysite.conf:87)
                 alias mysite2.co.uk
                 alias cdn.mysite2.co.uk
*:443                  is a NameVirtualHost
         default server indigo-1.mysite.co.uk (/etc/httpd/conf.d/000-mysite.conf:44)
         port 443 namevhost indigo-1.mysite.co.uk (/etc/httpd/conf.d/000-mysite.conf:44)
         port 443 namevhost indigo-1.mysite.co.uk (/etc/httpd/conf.d/ssl.conf:56)
         port 443 namevhost www.mysite.co.uk (/etc/httpd/conf.d/zzz-mysite.conf:63)
                 alias mysite.co.uk
                 alias cdn.mysite.co.uk
         port 443 namevhost pugpig.mysite.co.uk (/etc/httpd/conf.d/zzz-mysite.conf:77)
         port 443 namevhost www.mysite2.co.uk (/etc/httpd/conf.d/zzz-mysite.conf:91)
                 alias mysite2.co.uk
                 alias cdn.mysite2.co.uk
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex authdigest-opaque: using_defaults
Mutex proxy-balancer-shm: using_defaults
Mutex rewrite-map: using_defaults
Mutex authdigest-client: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/run/httpd/" mechanism=default 
Mutex mpm-accept: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: _RH_HAS_HTTPPROTOCOLOPTIONS
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48
Group: name="apache" id=48

答案1

我通过删除 ProxyPreserveHost 设置来实现这个功能,所以我的最终配置是:

  SSLProxyEngine on
  SSLProxyVerify none
  SSLProxyCheckPeerCN off
  SSLProxyCheckPeerName off
  SSLProxyCheckPeerExpire off
  ProxyPass "/blog" "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog" retry=1 acquire=3000 timeout=600 Keepalive=on
  ProxyPassReverse "/blog"  "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/blog"
  ProxyPass "/assets" "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/assets" retry=1 acquire=3000 timeout=600 Keepalive=on
  ProxyPassReverse "/assets" "https://master-7rqtwti-i7feq5lebr6se.eu-2.platformsh.site/assets"

相关内容