2

I am trying to host my AngularJs app and my dotnet core api on nginx but I'm unable to access my api, following is my default.conf in /etc/nginx/conf.d:

server {

listen 80 default_server;
listen [::]:80 default_server;

root /var/www/dashboard;

index index.html;

server_name example.server.com;

location / {
     try_files $uri /index.html;
}

location /api {
 proxy_pass http://localhost:5000;
 proxy_http_version 1.1;
 proxy_set_header Upgrade $http_upgrade;
 proxy_set_header Connection keep-alive;
 proxy_set_header Host $host;
 proxy_cache_bypass $http_upgrade;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

}
Ali
  • 1,648
  • 2
  • 26
  • 48
  • I assume that after updating the config, you have reloaded / restarted the nginx process? Does it reload properly? Any errors reported in the logs? When you try to access the `/api` endpoint, what happens in both your browser, and what do you see in the nginx logs? – Matt Clark Sep 06 '18 at 18:31
  • I've checked the syntax of conf by "nginx -c /etc/nginx/nginx.conf -t" and restarted the nginx "sudo systemctl restart nginx" and then checked the status where it's running fine "sudo systemctl status nginx". – Ali Sep 06 '18 at 18:34
  • Okay, great. And what do you see in both the logs, and in your browser, when you try to access the newly configured proxy? – Matt Clark Sep 06 '18 at 18:35
  • When I access say example.server.com it shows me my index.html file in the dashboard dir but when I try example.server.com/api/... I get 404 error, whereas if I access http://localhost:5000/api/.. in local browser its working fine. – Ali Sep 06 '18 at 18:37
  • LOGS, what do the LOGS say? – Matt Clark Sep 06 '18 at 18:38
  • This is what log says but not sure why it's looking in the dir where it should redirect the request or reverse proxy: 2018/09/06 08:51:29 [error] 5331#5331: *1 open() "/etc/nginx/html/api/values" failed (2: No such file or directory), client: my_ip_address, server: localhost, request: "GET /api/values HTTP/1.1", host: server_ip_address, the url I am using to access the api endpoint is http://server_name/api/api/values. – Ali Sep 06 '18 at 18:45

0 Answers0