Score:0

How to redirect http to https in NGINX in existing nginx.conf

mg flag

I'm on RHEL7.9 Linux. I have a server (IP a.b.c.d) serving a webApplicationA and using https in nginx and it's working accessible at https://a.b.c.d.

On that same machine (same IP, a.b.c.d) I have an AppImage running which is a DIFFERENT web application, webApplicationB serving map tiles accessible at http://a.b.c.d:3650. WebApplicationA needs to load the map tiles from http://a.b.c.d:3650, that is from webApplicationB.

The only way I'm currently able to get this to work (loading http://a.b.c.d:3650 inside webApplicationA) is by configuring Chrome to "Allow insecure content". This is not acceptable.

I'm not sure I'm able to access the innards of the AppImage to embed any SSL keys. How would I go about modifying the nginx.conf for webApplicationA to proxy to http://a.b.c.d:3650, such that the loaded map tiles from webApplicationB is using https? I've spent a week researching and trying various "/location" parameters "rewrite" lines in the nginx.conf file with no luck. The more I research and try the more I feel I'm just trying anything and everything just hoping it magically works at this point. Can someone please explain how this is done?

Here's my existing server block. What would I add or change?

    server {
        listen       443 ssl;
        server_name  mapperapp;
        rewrite /login / redirect;

        ssl_certificate      nginx.crt;
        ssl_certificate_key  nginx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  60m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
        location / {
            root   html;
            index  index.html index.htm;
        }
    }

UPDATE: I added the following server block to my existing nginx.conf, and then navigated to https://a.b.c.d:4653 and it worked.

    server {
        listen 4653 ssl;
        server_name mapperapp;

        ssl_certificate      nginx.crt;
        ssl_certificate_key  nginx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  60m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
          proxy_set_header X-Forwarded-Host mapperapp;
          proxy_set_header X-Forwarded-Proto https;
          proxy_pass http://a.b.c.d:3650;
        }
    }

Score:0
vn flag

Set up a server block for another port, such as 4653, so that this nginx instance can serve https://a.b.c.d:3653. Then let this new server block proxies to http://a.b.c.d:3650.

Back to your webApplicationA, links starting with https://a.b.c.d:3653 can be used and browsers won't warn any more.

thornbe avatar
mg flag
Thank you. Can you provide an example of such a server block using port 4653. Above is my existing server block; I'm not sure what besides the port that I need to include.
thornbe avatar
mg flag
Thanks. You gave me the path to pursue and I got it working. The nginx.conf configuration that worked is up above.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.