0

I am using a nginx to redirect from several http services with IP:PORT to a https domain. Now I need the nginx to redirect only:

http://IP to https://DOMAIN and open it in Browser with: https://DOMAIN:PORT because I have several Ports on the Server and want evrything in the same ssl domain. Is this possible? All my tests I made failed so far...

###
### PROXY CONFIG FOR bot*******.*****.de
###

    server {
    server_name bot*******.*****.de; # managed by Certbot
        root         /usr/share/nginx/default;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

     port_in_redirect off;

        location / {
          proxy_set_header        Host $http_host;
          proxy_set_header        X-Real-IP $remote_addr;
          proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header        X-Forwarded-Proto $scheme;
          proxy_pass          http://###.####.###.####;
          proxy_read_timeout  90;
          proxy_redirect      http://###.####.###.#### https://bot*******.*****.de;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/bot*******.*****.dee/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/bot*******.*****.de/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

    server {
    if ($host = bot*******.*****.de) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen       80 ;
        listen       [::]:80 ;
    server_name bot*******.*****.de;
    return 404; # managed by Certbot

}

## ENDE BOTCONF
  • The configuration file seems unrelated to your question as it uses the standard https port. Please expand your question with examples using the non-standard ports you are attempting to implement. – Richard Smith Oct 2 '18 at 11:05
  • I don't understand the question. Can you please provide examples? – Tommiie Oct 2 '18 at 11:08
  • okey, i try to explain: i like to redirect an http service like http ://192.168.1.2 to https ://example.org on my 192.168.1.2 are running services on may ports. i dont want a direct for evry single service because the ports a dynmic. because of that i thought i can redirect only the http ://IP to domain and open then in my browser the desired service with https ://domain:port - thats the solution i need. in my example config i dont use a port, but if i open a https ://domain:port i get a 404 from nginx. – Kjellson Oct 2 '18 at 11:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.