Score:0

Nginx proxy pass Server runs in port 4443 with lets encrypt ssl

us flag

I am trying to proxy java application runs on port 4443 using nginx. My nginx server block is like below:

map $http_upgrade $connection_upgrade {
     default upgrade;
     ''      close;
}

 upstream ovserver {
    server example.com:4443;
 }

 server {
    server_name ov.example.com www.ov.example.com;


    location / {
            proxy_pass https://ovserver;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_intercept_errors on;
            proxy_redirect off;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-NginX-Proxy true;
            proxy_ssl_session_reuse off;
    }

        listen [::]:443 ssl;
        listen 443 ssl;
        ssl_certificate /etc/letsencrypt/live/ov.example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/ov.example.com/privkey.pem;
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

}

server {
    if ($host = ov.example.com) {
        return 301 https://$host$request_uri;
    } 
        listen 80;
        listen [::]:80;
        server_name ov.example.com www.ov.example.com;
        return 404;
}

I need to direct all the requests generate by the java application in port 4443 to given host. Ex:

https://example.com:4443/something/here  => https://ov.example.com/something/here
wss://example.com:443/something/here     => wss://ov.example.com/something/here

But with my current configuration, it is still not working. Any suggestions appreciated.

UPATE 1

curl request examples:

curl --user name:password https://example.com:4443/something/api/here
curl: (60) SSL certificate problem: self signed certificate

curl --user name:password https://ov.example.com/something/api/here
{"numberOfElements":0,"content":[]} # expected response

UPDATE 2

curl --user name:password https://example.com:4443/something/api/here --key /etc/letsencrypt/live/ov.example.com/privkey.pem --cert /etc/letsencrypt/live/ov.example.com/cert.pem

 #response
 SSL certificate problem: self signed certificate
sv flag
Welcome to ServerFault. Please provide an example request with curl, current output and expected output.
Madushan Perera avatar
us flag
@PothiKalimuthu I updated my question.
Gerard H. Pille avatar
in flag
What is the current response?
Madushan Perera avatar
us flag
@GerardH.Pille I have updated the curl responses in the question. In the browser console, I am getting `https://example.com:4443/something/api/here net::ERR_CERT_AUTHORITY_INVALID`. If I can get rid of this `example.com:4443` with `ov.example.com` it will work.
Madushan Perera avatar
us flag
@GerardH.Pille Please check my update 2 in the question.
djdomi avatar
za flag
you setup nginx to listen on 443 not 4443 if a service is reachable by 4443 then it's your background service that should not listen to the internet ;)
Gerard H. Pille avatar
in flag
Great update, you just repeated what you said under update 1. What is the result of the second curl request?
Madushan Perera avatar
us flag
@GerardH.Pille I am sorry. If you are asking the result of update 1 - second curl request, then it gives me the expecting api response which is `{"numberOfElements":0,"content":[]}`. That is why I want to replace `https://example.com:4443/something/here => https://ov.example.com/something/here` . Hope you understand my requirement.
Gerard H. Pille avatar
in flag
I'm afraid I don't. If the second request works as expected, then your problem is solved: let the java app use the second url.
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.