HTTP to HTTPS Using Nginx


I've configured HTTP to HTTPS redirect in my /etc/nginx/sites-available/default file. Its as below:

server {

listen 80 default_server;

listen [::]:80 default_server;


return 301 https://$servername$requesturi;


server {

SSL configuration

listen 443 ssl http2 default_server;

listen [::]:443 ssl http2 default_server;

include snippets/;

include snippets/ssl-params.conf;

. . .

My problem is that everytime I try to go to "" it redirects to "". I would like it to redirect to "". What am I doing wrong in the default file?

Thank you for your help!

1 Reply

Assuming you want both and to be redirected to, try this instead:

return 301$request_uri;

You should probably put a server_name line inside the https server block as well.


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct