'Cant redirect nginx. Proxy pass doesnt work

So what fo I have I have a serivce running at my localhost at port 8004(api1) and port 8005(api2) From main server i am sending https://s2.example.com:8001/api/request/v1 and post data

It should be handled at server (s2) like http request and reply should be given.

my nginx now looks like at s2 server

 server {
          
          
        listen 443 ssl; 
        server_name s2.exmaple.com;             
        ssl_certificate ...
        ssl_certificate_key ..
        include /etc/letsencrypt/options-ssl-nginx.conf;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
       
         location /api1   {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header content-type "application/json";
            proxy_pass http://127.0.0.1:8004/api/request/v1;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_cache_bypass $http_upgrade;
            proxy_redirect off;
         
           }

 location /api2   {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header content-type "application/json";
            proxy_pass http://127.0.0.1:8005/api/request/v1;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_cache_bypass $http_upgrade;
            proxy_redirect off;
         
           }

But this doenst work at all. I tried to use proxy redirect and so on but no luck



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source