I have an EC2 server (in Private subnet) from where I run some Python microservice. From my application running on an Apps EC2 (in public subnet) I am trying to access the Python microservices.

I setup nginx as reverse proxy on Apps EC2 (public subnet) . From my minimal understanding of nginx I added a conf file as below :

server {

        listen   80;
        server_name 3.23.xxx.xxx EC2-public.test.com;

        location / {
                root   /var/www/Myapp/App;
                index  index.php index.html index.htm;
                autoindex on;  
        #Application APIs on EC2 public 
        location /api {
                proxy_pass http://myappsip-EC1.:4000;

        #My second EC2 Python microservice APIs
        location /pyserv {
                proxy_pass http://myprivateEC2-IP:5000/;


The issue is that from my public url I am able to access the service on the microservice EC2 if I give the absolute path in proxy_pass but any path relative to it I am not able to access. Any relative path seems to be picked by from the Primary EC2s root path.

=> EC2-public.test.com/ (primary application - works)
=> EC2-public.test.com/pyserv      (API1 on second EC2 - http://myprivateEC2-IP:5000/- works since given in proxy_pass) 
=> EC2-public.test.com/pyserv/srv1 (API 2 on second EC2 - http://myprivateEC2-IP:5000/srv1 - does not work) 

I know I am missing something in that I don't seem to have referred to the second EC2 root path. But I am not able to figure out how.


  • my guess is you forgot a slash. Should be location /pyserv/ – dgan Mar 27 at 18:29
  • Thank you that was the issue . If you can put it as answer I can approve it. Sincerely appreciate your help. – user14013917 Mar 28 at 6:06

You forgot a slash at the end of location /pyserv/ :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.