Redirect www.example.com to https://example.com

Hi all,

I configured erpnext to work at https://example.com and it’s working fine. But when we open the website for the first time in other computers , it opens at https://www.example.com which causes ssl cert error and erpnext site error like “Sorry! We will be back soon.” I need the site to redirect to https://example.com by default.

I tried searching for answers in this forum and tried below steps

  1. Added A record in both godaddy and digitalocean

  2. Added

    server {
    listen 80;
    server_name
    www.example.com;
    return 301 https://$host$request_uri;
    }

in frappe-bench/config/nginx.config but failed to make it work. Please correct me if I am missing anything.

try this

Thanks

Hi @raghu9 I have the same Issue, did you fix it? Thanks

edit nginx config
server {
server_name www.example.com;
rewrite ^ http://example.com$request_uri? permanent;
}

Restart nginx
sudo service nginx restart

Thanks @kolate_sambhaji But when I do a new setup production I will have to modify the configuration again.
Maybe it would be good if the bench command generates the rewrite.
I’will .
I’m going to use your solution equally.

@froldan I found it easier to use this Setting up TLS SSL certificates Let's Encrypt for ERPNext sites · frappe/erpnext Wiki · GitHub rather than config manually.

@kickapoo Thanks for you answer.
I had configured SSL following these post but still doesn’t works the domain with www.
Another thing that I should check or config?

Regards

@froldan Check your dns records. (if you have both www.hostname and hostname)

Also did you select from letsencypt to auto redirect? I think is in the final step option 2.

The above thing worked for me. To be precise, one needs to

  • add extra server {} block
  • and file path is /home/frappe/frappe-bench/config/nginx.conf

server {
listen 80;
server_name www.host.com;
rewrite ^ http://host.com$request_uri? permanent;
}
server{…default thing that was prior to edit…}

1 Like