0

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;
}
Dave M
  • 4,514
  • 22
  • 31
  • 30
  • 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. – Lex Li Oct 09 '22 at 22:54
  • 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. – Tim P Oct 11 '22 at 15:30
  • 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 Oct 12 '22 at 05:12
  • 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 – Muhammad Umar Oct 12 '22 at 05:13

1 Answers1

0

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
Tim
  • 31,888
  • 7
  • 52
  • 78