Before reading further, I have tried to understand / find a solution. From the similar questions, I did not find my answer or at least understood what I am doing wrong.
So I have 2 instances of Amazon EC2 and a load balancer ELB.
For each instance, I use NGINX with Gunicorn and Django.
I setup a redirection for all HTTP request to HTTPS. But for some unexplained reasons, redirections do not work.
I tried to change my hosts file so I can connect directly to one of the instance and the redirection works. But When I use the ELB, it does not work.
Here is an example of nginx configuration :
upstream myserver {
server 127.0.0.1:10032 fail_timeout=0;
}
server {
listen 80;
server_name pub.myserver.ca;
return 301 https://$server_name$request_uri;
}
server {
listen 443;
server_name pub.myserver.ca;
ssl on;
ssl_certificate /etc/ssl/pub_myserver_ca.pem;
ssl_certificate_key /etc/ssl/pub_myserver_ca.key;
ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
access_log /var/log/nginx/myserver-access.log;
error_log /var/log/nginx/myserver-error.log;
keepalive_timeout 300;
proxy_read_timeout 300;
client_max_body_size 200M;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://myserver;
break;
}
}
location /static {
autoindex off;
alias /home/tool/www/static;
}
}
Do you have any ideas? Or insight? Or documentation that I should look into?
Thank you in advance.
EDIT
cUrl response when request goes through the ELB :
$ curl -I http://pub.myserver.ca/client/sign-in/
HTTP/1.1 200 OK
Content-Language: en
Content-Type: text/html; charset=utf-8
Date: Tue, 23 May 2017 20:39:34 GMT
Server: nginx
Set-Cookie: csrftoken=********; expires=Tue, 22-May-2018 20:39:34 GMT; Max-Age=31449600; Path=/
Set-Cookie: sessionid=********; expires=Tue, 06-Jun-2017 20:39:34 GMT; httponly; Max-Age=1209600; Path=/
Vary: Accept-Language, Cookie
X-Frame-Options: SAMEORIGIN
Connection: keep-alive
cUrl response when request goes directly to the server :
$ curl -I http://pub.myserver.ca/client/sign-in/
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Tue, 23 May 2017 20:40:18 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://pub.myserver.ca/client/sign-in/