我有一个Elastic Load Balancer,可以将请求转发给我的实例,这些实例会终止SSL等,而不是负载均衡器,因此它们被设置为执行TCP转发。
我在app.php中添加了以下内容以获取正确的IP:
支持:: setTrustedProxies(阵列($请求 - >服务器 - >获得(' REMOTE_ADDR')));
但是$ request-> getClientIP()正在返回无效的奇数地址,这样的多播地址如下:
172.31.25.85
172.31.25.85
172.31.42.183
等。
我该如何解决这个问题?
这是SERVER的转储
Array ( [REDIRECT_COMPOSER_HOME] => /root [REDIRECT_PHP_MEMORY_LIMIT] => 512M [REDIRECT_PHP_MAX_EXECUTION_TIME] => 60
[REDIRECT_PHP_DISPLAY_ERRORS] => Off [REDIRECT_PHP_COMPOSER_OPTIONS] => [REDIRECT_PHP_ALLOW_URL_FOPEN] => On [REDIRECT_PHP_ZLIB_OUTPUT_COMPRESSION] => Off [REDIRECT_PHP_DOCUMENT_ROOT] => /web/
[REDIRECT_PHP_DATE_TIMEZONE] => UTC [REDIRECT_STATUS] => 200 [COMPOSER_HOME] => /root [PHP_MEMORY_LIMIT] => 512M [PHP_MAX_EXECUTION_TIME] => 60 [PHP_DISPLAY_ERRORS] => Off
[PHP_COMPOSER_OPTIONS] => [PHP_ALLOW_URL_FOPEN] => On [PHP_ZLIB_OUTPUT_COMPRESSION] => Off [PHP_DOCUMENT_ROOT] => /web/ [PHP_DATE_TIMEZONE] => UTC
[HTTP_HOST] => c.filtered.com [HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5 [HTTP_ACCEPT_ENCODING] => gzip, deflate, br [HTTP_REFERER] => https://c.filtered.com/da/c/filtered [HTTP_COOKIE] => PHPSESSID=gcrn9sfbq1rhkactkau6s5fbn2; hl=da; returning_visitor=1; __utma=84468683.1790758543.1493197744.1493197744.1493207849.2; __utmc=84468683; __utmz=84468683.1493207849.2.2.utmcsr|utmccn=(referral)|utmcmd=referral|utmcct=/da/; PAPVisitorId=2491e88a40a6a8d0b2918dOIatw1xtp9; __utmb=84468683.1.10.1493207849; __utmt=1 [HTTP_UPGRADE_INSECURE_REQUESTS] => 1 [CONTENT_TYPE] => application/x-www-form-urlencoded [HTTP_X_FORWARDED_PROTO] => https [HTTP_X_FORWARDED_FOR] => 172.31.25.85 [HTTP_X_FORWARDED_HOST] => c.filtered.com [HTTP_X_FORWARDED_SERVER] => c.filtered.com [HTTP_CONNECTION] => Keep-Alive [CONTENT_LENGTH] => 253 [PATH] => /usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache [SERVER_NAME] => c.filtered.com [SERVER_ADDR] => 127.0.0.1 [SERVER_PORT] => 80 [REMOTE_ADDR] => 127.0.0.1 [DOCUMENT_ROOT] => /var/www/html/web/ [REQUEST_SCHEME] => http [CONTEXT_PREFIX] => [CONTEXT_DOCUMENT_ROOT] => /var/www/html/web/ [SERVER_ADMIN] => root@localhost [SCRIPT_FILENAME] => /var/www/html/web/app.php [REMOTE_PORT] => 54638 [REDIRECT_URL] => /da/c/filtered [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => POST [QUERY_STRING] => [REQUEST_URI] => /da/c/filtered [SCRIPT_NAME] => /app.php [PHP_SELF] => /app.php [REQUEST_TIME_FLOAT] => 1493208003.205 [REQUEST_TIME] => 1493208003 )
以下是我的apache配置的相关部分:
ProxyPass / http://localhost:80/ retry=0
ProxyPassReverse / http://localhost:80/
ProxyPreserveHost on
RequestHeader set X-Forwarded-Proto "https" early