Score:0

My website is working when https://www.example.com but not when https://example.com

eg flag

I have purchased the domain from Godaddy.

My website is working when

Not working when

I want to know where I need to add the suitable configuration. I have already added this to /etc/ngnix/sites-available/example.com

server {
listen 80;
server_name https://example.com
return 301 https://www.example.com$request_uri;
}
Lex Li avatar
vn flag
You will have to reveal more about your configuration, as HTTPS shouldn't work if you have no binding on port 443 (the server block you showed only cover port 80). You have to provide a complete image of the setup and others can help review. Besides, you must describe clearly what you meant by "not working", as the actual error message from a browser or `curl` matters a lot on what might be wrong.
Tim P avatar
af flag
Probably need a little more information about what "not working" means. If it is a certificate error, you probably need to have "example.com" included in your TLS certificate and not just "www.example.com" or add another TLS certificate. If it is a server not responding error start looking at your site configurations.
Muhammad Umar avatar
eg flag
After playing with DNS on goDaddy, browser is throwing a different response now and saying Welcome to nginx!( only when I browse like https://example.com) but working fine when I browse like http://example.com, example.com, www.example.com, http://www.example.com
Muhammad Umar avatar
eg flag
So, In short, I need to handle this case now https://example.com. The server is getting request but not serving with an HTML response
Score:0
gp flag
Tim

Https is port 443, you need to listen on that port including using a certificate for that domain. The config would be something like this

server {
  listen 443 ssl http2;
  server_name example.com;

  ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;

  return 301 https://www.example.com$request_uri;
}

To answer the question in the comment:

  • The sites-available folder is for all of the configurations that your server holds
  • The sites-enabled folder is for the configurations you want active.
  • Typically you create a symbolic link (ln -s) from the sites-enabled folder to the sites-available folder
Muhammad Umar avatar
eg flag
i have two files, site-available and site-enable, where to put this
Tim avatar
gp flag
Tim
Please see updated answers. Suggest you do some training / reading in this area to learn the basics of how Nginx works.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.