-1

I'm serving a webpage from an embedded linux box that may or may not be connected to the internet. The idea is, a user enters the IP of the machine and the page comes up. I want to redirect all non-ssl urls to an ssl url (https). Every example I've found uses $server_name or $host in the return line of the nginx configuration. The problem for me is that the IP of the machine might change and editing the nginx config file every time is not an option. I've tried setting the server_name to _ to no avail. What does work is if I set server_name to the current IP of the machine. Then, if I type in 192.168.1.196 it redirects to https://192.168.1.196/dashboard, which is what I want. Unfortunately this will not work in production, since as mentioned the IP may change. My current nginx config is below.

server {
    listen       80;
    #server_name  _;
    #server_name 192.168.1.196;
    ssl_certificate server.crt;
    ssl_certificate_key private.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;
    autoindex on;
    return 302 https://$server_name/dashboard;

    location /dashboard {
        alias build;
        index index.html;
    }
}

closed as unclear what you're asking by womble May 9 at 2:48

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Can you provide some more details about your configuration files, directories, and possibly a curl command output? – JD Williams May 9 at 20:36
1

Then it's $host that you want to use, because this is what contains the Host: header that the browser supplied.

  • Tried this, does not redirect. – Alex Loper May 8 at 23:55
  • Then you should start from there and try to figure out why. – Michael Hampton May 9 at 0:01
  • I've been trying to figure out why for the past few hours, that's why I came here. – Alex Loper May 9 at 0:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.