Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

GET http://localhost/api/v1 404 nginx springboot

I’m having a problem. I want to send a request to the nginx server so that it sends it to the spring boot server and returns it to me. But this error pops up:

enter image description here

The message "Hello" should be displayed on the screen, my controller is:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api")
@Slf4j

public class PostsController {
    @GetMapping("/v1")
    public String helloWorld(){
        return "Hello";
    }

} 

I got to this, since there were the same problems with the GRAPHQL API, the cross origin config in spring boot did not help. Help me please. I got to this, since there were the same problems with the GRAPHQL API, the cross origin config in spring boot did not help. Help me please, my nginx.conf is:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;


    location / {
      root     /var/www;
    }

    location /api/ {
      rewrite /api(.*) /$1  break;

      proxy_pass http://localhost:8080;
      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 X-Forwarded-Proto $scheme;
    }
    
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    } 

UPDATE 1
By typing in the url just localhost:8080/api/v1 the message is displayed: Hello

>Solution :

If you want http://localhost/api/v1 to be passed to http://localhost:8080/api/v1 then your location needs to look like this:

location /api/ {

      proxy_pass http://localhost:8080/api/;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading