簡體   English   中英

反向代理背后的Symfony端口重定向

[英]Symfony port redirection behind reverse proxy

我有一個使用FosUserBundle的Symfony 3.2應用程序(在端口8443上運行)。 當匿名用戶訪問“ https:// [myurl] .com:8443 ”時,他們會被重定向到“ https:// [myurl] .com:8443 / login ”以進行登錄。 這種重定向在訪問應用程序時工作正常但現在,我們希望使用反向代理將客戶的請求轉發給應用程序。 客戶將使用標准的https端口443。

會發生以下情況:用戶使用“ https://myurl.com ”訪問該應用程序。
該請求由反向代理轉發到在端口8443上托管應用程序的Web服務器(IIS)。
發出請求的用戶被重定向到“ https://myurl.com:8443/login ”,這不起作用,因為8443僅在服務器端打開。

我在symfony中嘗試了不同的解決方案但是無法使其工作:
- 在symfony中設置反向代理: Request::setTrustedProxies(array('123.456.78.89'));
-set http_port/https_port in config.yml
-set $_SERVER['SERVER_PORT'] = 443;

關於如何解決這個問題的任何想法?

謝謝

打開以下文件:

web/app.php

就在這一行之后:

$request = Request::createFromGlobals();

插入此塊:

// tell Symfony about your reverse proxy
Request::setTrustedProxies(
    // the IP address (or range) of your proxy
    ['192.0.0.1', '10.0.0.0/8'],

    // trust *all* "X-Forwarded-*" headers
    Request::HEADER_X_FORWARDED_ALL

    // or, if your proxy instead uses the "Forwarded" header
    // Request::HEADER_FORWARDED

    // or, if you're using AWS ELB
    // Request::HEADER_X_FORWARDED_AWS_ELB
);

看到:

“如何配置Symfony在負載均衡器或反向代理服務器后面工作” http://symfony.com/doc/3.4/deployment/proxies.html

除了@Gor之外,我認為您還應該配置代理以添加X-Forwarded標頭。 在Nginx中有類似的東西

location / {
    proxy_pass              http://myurl:8443;
    proxy_set_header        Host $host;
    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        X-Forwarded-Port $server_port;
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM