# Https redirection not working correctly

**URL:** <https://www.ruby-forum.com/t/https-redirection-not-working-correctly/243754>\
**Category:** NGINX\
**Created:** [December 30, 2015, 6:15pm UTC](https://www.ruby-forum.com/t/https-redirection-not-working-correctly/243754 "2015-12-30T18:15:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [December 30, 2015, 6:15pm UTC](https://www.ruby-forum.com/t/https-redirection-not-working-correctly/243754/1 "2015-12-30T18:15:41Z")

</div>

Hello!

I am trying to set up nginx to

- switch from http traffic to https
- send alls https traffic to my odoo backend on port 8069

This is already working for different subdomains, but not for the domain  
itself.

http://(www.)subdomain.domain.ch =\> https://(www.)subdomain.domain.ch  
http://(www.)domain.ch =\> http://(www.)domain.ch, backend ist beeing  
loaded  
but not secured

1. Why is domain.ch not beeing redirected to [https://domain.ch](https://domain.ch)?

2. I would like to set up the let’s encrypt ssl renewal script described  
here:  
[https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04](https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-14-04)  
For this I need to put a file into the webroot folder, but I don’t know  
how  
to define this folder…

Thank you for your help.

This is my “odoo” file in sites-available:

## odoo backend

upstream odoo {  
server 127.0.0.1:8069;  
}

## https site##

server {  
listen 443 default;  
server\_name \*.xxxxx.ch xxxxx.ch www.xxxxx.ch;  
# root /usr/share/nginx/html;  
# index index.html index.htm;

```
# log files
access_log /var/log/nginx/odoo-access.log;
error_log /var/log/nginx/odoo-error.log;

# ssl files
ssl on;
ssl_certificate /etc/letsencrypt/live/xxxxx.ch/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/xxxxx.ch/privkey.pem;
keepalive_timeout 60;

# limit ciphers
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

# proxy buffers
proxy_buffers 16 64k;
proxy_buffer_size 128k;

## default location ##
location / {
    proxy_pass http://odoo;
    # force timeouts if the backend dies
    proxy_next_upstream error timeout invalid_header http_500 

```

http\_502  
http\_503 http\_504;  
proxy\_redirect off;

```
    # set headers
    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 https;
}

# cache some static data in memory for 60mins
location ~* /web/static/ {
    proxy_cache_valid 200 60m;
    proxy_buffering on;
    expires 864000;
    proxy_pass http://odoo;
}

```

}

## http redirects to https

server {  
listen 80;  
server\_name \*.xxxxx.ch www.xxxxx.ch xxxxx.ch;

```
# Strict Transport Security
add_header Strict-Transport-Security max-age=2592000;
rewrite ^/.*$ https://$host$request_uri? permanent;

```

}

Posted at Nginx Forum:

> **[https redirection not working correctly](https://forum.nginx.org/read.php?2,263786,263786#msg-263786)**
>
> Hello! I am trying to set up nginx to - switch from http traffic to https - send alls https traffic to my odoo backend on port 8069 This is already working for different subdomains, but not for the domain itself. http://(www.)subdo

---

<div class="post-metadata">

**Author:** ![Parzip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Parzip](https://www.ruby-forum.com/u/Parzip)\
**Post date:** [December 30, 2015, 6:22pm UTC](https://www.ruby-forum.com/t/https-redirection-not-working-correctly/243754/2 "2015-12-30T18:22:43Z")

</div>

Hello!

After your upstream block, but before your server (https) block put  
something like this:

server {  
listen 80;  
server\_name xxxxxxxxx.ch www.xxxxxxxxx.ch;  
return 301 https://$server\_name$request\_uri;  
}

…and remove the ## http redirects to https ## at the bottom.

## Best regards, Kevin

Kevin W.  
kworthington att gmail dat com

> **[Kevin Worthington](https://kevinworthington.com/)**
>
> Practical Tech Guides, Troubleshooting, and Insights on the Modern Internet

[http://twitter.com/kworthington](http://twitter.com/kworthington)

---

<div class="post-metadata">

**Author:** ![Parzip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Parzip](https://www.ruby-forum.com/u/Parzip)\
**Post date:** [December 30, 2015, 6:39pm UTC](https://www.ruby-forum.com/t/https-redirection-not-working-correctly/243754/3 "2015-12-30T18:39:04Z")

</div>

Hello Kevin!  
Thank you very much, but it’s still not working…

## odoo backend

upstream odoo {  
server 127.0.0.1:8069;  
}

## http redirects to https

server {  
listen 80;  
server\_name \*.XXXXX.ch www.XXXXX.ch XXXXX.ch;  
return 301 https://$server\_name$request\_uri;  
}

## https site##

server {  
listen 443 default;  
server\_name \*.XXXXX.ch XXXXX.ch www.XXXXX.ch;  
# root /usr/share/nginx/html;  
# index index.html index.htm;

```
# log files
access_log /var/log/nginx/odoo-access.log;
error_log /var/log/nginx/odoo-error.log;

# ssl files
ssl on;
ssl_certificate /etc/letsencrypt/live/XXXXX.ch/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/XXXXX.ch/privkey.pem;
keepalive_timeout 60;

# limit ciphers
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers AES256+EECDH:AES256+EDH:!aNULL;

# proxy buffers
proxy_buffers 16 64k;
proxy_buffer_size 128k;

## default location ##
location / {
    proxy_pass http://odoo;
    # force timeouts if the backend dies
    proxy_next_upstream error timeout invalid_header http_500 

```

http\_502  
http\_503 http\_504;  
proxy\_redirect off;

```
    # set headers
    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 https;
}

# cache some static data in memory for 60mins
location ~* /web/static/ {
    proxy_cache_valid 200 60m;
    proxy_buffering on;
    expires 864000;
    proxy_pass http://odoo;
}

```

}

Posted at Nginx Forum:  
[https://forum.nginx.org/read.php?2,263786,263792#msg-263792](https://forum.nginx.org/read.php?2,263786,263792#msg-263792)

---

<div class="post-metadata">

**Author:** ![Parzip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e8c25b/32.png) [@Parzip](https://www.ruby-forum.com/u/Parzip)\
**Post date:** [December 30, 2015, 6:44pm UTC](https://www.ruby-forum.com/t/https-redirection-not-working-correctly/243754/4 "2015-12-30T18:44:20Z")

</div>

could this be related to the forwarding of the address?

This is my domain registrar setting:

XXXXX.ch =\> web alias to subdomain.XXXXX.ch  
subdomain.XXXXX.ch =\> A record to IP address of my server

I need this setup because my odoo-erp selects the database according to  
my  
subdomains.

Posted at Nginx Forum:

> **[Re: https redirection not working correctly](https://forum.nginx.org/read.php?2,263786,263793#msg-263793)**
>
> Hello! I am trying to set up nginx to - switch from http traffic to https - send alls https traffic to my odoo backend on port 8069 This is already working for different subdomains, but not for the domain itself. http://(www.)subdo
