Location attribute not properly configured in nginx.conf.
January 16, 2021 06:32AM
HI all, I am setting up my first nginx server.

I have a REST API developed in .net core which has few methods in it. I am trying to use nginx as reverse proxy here. my api is running in this URL "http://localhost:5000/weatherforecast". similarly I have few other routes like "http://localhost:5000/hello" and "http://localhost:5000/test"..

here is a snippet from nginx.conf file.


-------------------------------------------------
upstream webapi {
server 127.0.0.1:5000;
}


server {
listen 7070;
server_name mysite1;

location ~* ^/myapi {
proxy_pass http://webapi;
}
}

------------------------------------------------------

From my browser when I hit the address "http://127.0.0.1:7070/myapi/weatherforecast", am getting "Page not found" exception.

But when I have the configuration as below it working fine (without upstream).

----------------------------------------
server {
listen 7070;
server_name mysite1;

location ~* ^/myapi {
proxy_pass http://127.0.0.1:5000/weatherforecast
}
}

-----------------------------------------------
Kindly suggest me how to make the routes (weatherforeacast, hello, test) to work. do I need to give separate location for each route.

Thanks,
Sanjay.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 287
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready