0

I have try to config nginx: /etc/nginx/nginx.conf

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name 10.0.0.10; #This is my private IP
    return 301 https://$server_name$request_uri;
    # OR return 301 https://$host$request_uri
}

But it cannot redirect from HTTP to HTTPS. Please help me on this. Thanks.

3
  • 1
    Try: return 301 https://$host$request_uri; Dec 5, 2018 at 10:01
  • I have already tried this but the direction still not working.
    – Brian
    Dec 5, 2018 at 11:03
  • Ok, $server_name will not work as it will use an IP address and the secure server will not like that. Have you tried: curl -I http://example.com? Dec 5, 2018 at 11:17

1 Answer 1

0

I think the issue is the IP as server name. Try and edit your hosts file and add an entry for the IP. For example:

10.0.0.10 myserver.test

The edit the nginx configuration and change the server_name parameter to:

server_name myserver.test;

restart nginx or reload the configuration.

1
  • HTTPS needs to use SSL with HTTP protocol to build a secure and verified connection. It is heavily relies on the domain name. In case you are specifing the IP, it won't work as expected. You can use ` server_name _;` as your server name, but your client must have a valid DNS configuration, at least hosts file needs to know to which IP redirect your request. Dec 5, 2018 at 16:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .