我遇到了一个问题。我想向nginx服务器发送一个请求,以便它将其发送到spring Boot 服务器并返回给我。但弹出此错误:
屏幕上应显示消息“您好”,我的控制器是:
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/api")
@Slf4j
public class PostsController {
@GetMapping("/v1")
public String helloWorld(){
return "Hello";
}
}
我得到了这个,因为有同样的问题与GRAPHQL API,跨原点配置在Spring Boot 没有帮助.请帮助我.我得到了这个,因为有同样的问题与GRAPHQL API,跨原点配置在 Spring 启动没有帮助.请帮助我,我的nginx.conf是:
#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输入url just localhost:8080/API/v1,显示消息:你好
1条答案
按热度按时间f5emj3cl1#
如果你想将http://localhost/api/v1传递给http://localhost:8080/api/v1,那么你的位置需要看起来像这样: