0

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
Madushan Perera
  • 113
  • 1
  • 6
  • Welcome to ServerFault. Please provide an example request with curl, current output and expected output. – Pothi Kalimuthu Jul 08 '21 at 02:19
  • @PothiKalimuthu I updated my question. – Madushan Perera Jul 08 '21 at 04:22
  • What is the current response? – Gerard H. Pille Jul 08 '21 at 04:37
  • @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 Jul 08 '21 at 04:48
  • @GerardH.Pille Please check my update 2 in the question. – Madushan Perera Jul 08 '21 at 07:40
  • 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 ;) – djdomi Jul 08 '21 at 16:11
  • Great update, you just repeated what you said under update 1. What is the result of the second curl request? – Gerard H. Pille Jul 08 '21 at 21:31
  • @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. – Madushan Perera Jul 08 '21 at 22:11
  • 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. – Gerard H. Pille Jul 09 '21 at 00:28

0 Answers0