首页 > 解决方案 > 转换这个 nginx 规则:fastcgi_param HTTP_X_FORWARDED_HOST $http_referer; 到 apache 2.4.x 配置

问题描述

我试图找到一种方法来转换这个 nginx 规则:fastcgi_param HTTP_X_FORWARDED_HOST $http_referer; 到 apache 2.4.x 配置。

堆栈:traefik -> apache -> php (cakePHP 2.10) -> API MS Symfony 5(全部在 docker 堆栈中)

当前的 nginx cconfiguration:

server {
root /var/www/html/app/webroot;
server_name mydev.local;

access_log /dev/stdout;
error_log /dev/stderr;

charset utf-8;
client_max_body_size 500M;

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

location /test {
    try_files $uri /test.php$is_args$args;
}

location ~ ^/(index|test).php(/|$) {
    fastcgi_pass php_mydev:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTP_X_FORWARDED_HOST $http_referer;
    fastcgi_param HTTPS off;
    fastcgi_buffers 4 256k;
    fastcgi_read_timeout 3000;
}

}

阿帕奇配置:

<VirtualHost *:80>
ServerName mydev.local
DocumentRoot /var/www/html
<Directory "/var/www/html">
    DirectoryIndex index.php
    Options -Indexes +FollowSymLinks
    AllowOverride All
    Require all granted
    RewriteEngine On
</Directory>
ProxyRequests On

ProxyPass "/"  "reverse-proxy" # reverse proxy is the docker service for traefik
ProxyPassReverse "/"  "reverse-proxy"

ProxyPreserveHost On
ProxyAddHeaders On
<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

LogLevel debug

AddDefaultCharset UTF-8
Header always set Cache-Control "max-age=86400" env=cache
ProxyTimeout 900
ExpiresActive On
<FilesMatch "\.(ico|gif|jpe?g|png|js|css|svg)$">
  ExpiresDefault "access plus 1 year"
</FilesMatch>

<IfModule mod_deflate.c>
    <IfModule mod_filter.c>
        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
        AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript
        AddOutputFilterByType DEFLATE application/rss+xml
        AddOutputFilterByType DEFLATE application/xml
        AddOutputFilterByType DEFLATE application/json
    </IfModule>
</IfModule>

问题:我们有一些来自 cakePHP 的 http 请求到一个微服务 API Symfony 5 当来自 MS 的响应完成后,cakePHP 使用 $this->referer 重新加载当前页面。使用 Nginx 没问题,referer 值反映了来自 cakePHP 的完整 URL,使用 Apache,我们只有 Host url:

Ngingx:referer = http://mydev.local/myfeat/view

阿帕奇:referer = http://mydev.local

谁能帮我解决这个问题?谢谢

标签: phpdockerapachenginxtraefik

解决方案


推荐阅读