AWS ELB does not fill in the x-forwarded-for header

We are using Amazon Elastic Load Balancer and have 2 Apache servers. However, we cannot get X-Forwarded-Headers on the app side

I read a similar post but could not find a solution for it

Amazon Elastic load balancer does not populate x-forwarded-proto header

This is how ELB listeners are configured.

HTTP 80  HTTP   80  N/A N/A
TCP  443 TCP    443 N/A N/A

      

If you change port 443 to HTTPS (Secure HTTP) instead of TCP, fill in the Other parameters headers: SSl (Secure TCP)

If it works, I would also like to know why and what makes the difference

+3


source to share


2 answers


Amazon now supports the use of the tcp header to pass the origin, as discussed in this article.



Apache does not support time proxy protocol . If you read the comments, there are source fixes to allow apache to handle it, or you can switch to nginx.

+3


source


I had the same request. I have an AWS load balancer pointing to a web server on port 80. All HTTPS request is allowed using AWS SSL certificate, but my client asked me to also redirect all 80 port request to HTTPS.

I am using Apache server so I needed to add the following lines to my virtual host config file (httpd.conf)

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]

      

Then I restarted the apache and Woala service! Below is the virtual host configuration, you will need to do the same for your subdomains like www.yourdomain.com



<VirtualHost *:80>
   RewriteEngine On
   RewriteCond %{HTTP:X-Forwarded-Proto} !=https
   RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]
   ServerAdmin webmaster@yourdomain.com
   DocumentRoot "/apache2/htdocs/YourDomainFolderWeb"
   ServerName yourdomain.com
   ErrorLog "logs/yourdomain.com-error_log"
   CustomLog "logs/yourdomain.com-access_log" common
</VirtualHost>

      

Hope it works. More information: https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

The best

+1


source







All Articles