spring-cloud / spring-cloud-gateway

An API Gateway built on Spring Framework and Spring Boot providing routing and more.
http://cloud.spring.io
Apache License 2.0
4.51k stars 3.31k forks source link

Why can't you configure access on Nginx #1931

Closed developers-youcong closed 4 years ago

developers-youcong commented 4 years ago

Describe the bug SpringCloudVersion is Hoxton.SR4

Sample Why can't you configure access on Nginx? image A visit like the one above will report 404 directly.

If it is configured in this way, it can be accessed normally. As shown in the figure below: image

My guess is there a conflict between SpringCloudGateWay and Nginx routing distribution?

spencergibb commented 4 years ago

What does this have to do with spring cloud?

developers-youcong commented 4 years ago

Have a relationship. I deployed the gateway, which is the entry point for all projects. However, I used Nginx as a reverse proxy for this entry, but I could not access it as a reverse proxy

spencergibb commented 4 years ago

I still don't understand the relationship to gateway, what, if any, error there is.

developers-youcong commented 4 years ago

There were no errors such as 500, but my gateway project was configured to Nginx and could not be accessed through Nginx, and Nginx could access a direct 404. If you want nginx to be accessible, it has to be in location /{}, not location /blog{}. My initial guess was that nginx was in conflict with the Spring Cloud-Gateway

spencergibb commented 4 years ago

At this point all you've shown is nginx configuration I can't help with. Please show your gateway configuration, how you make requests to the gateway and the behavior you are seeing from the gateway. No nginx

developers-youcong commented 4 years ago

My GateWay Core Config File Detail(application-dev.yml):

cloud:
    gateway:
      discovery:
        locator:
          lowerCaseServiceId: true
          enabled: true
      routes:
        - id: blog-auth
          uri: lb://blog-auth
          predicates:
            - Path=/auth/**
          filters:
            - ValidateCodeFilter
            - StripPrefix=1
        - id: blog-admin
          uri: lb://blog-admin
          predicates:
            - Path=/system/**
          filters:
            - name: BlackListUrlFilter
              args:
                blacklistUrl:
                  - /user/info/*
            - StripPrefix=1

bootstrap.yml:

# Tomcat
server:
  tomcat:
    uri-encoding: UTF-8
    min-spare-threads: 500
    max-threads: 2500
    max-connections: 5000
    accept-count: 1000
    max-http-header-size: 1048576
    protocol: org.apache.coyote.http11.Http11AprProtocol
  port: 8080

# Spring
spring:
  application:
    name: blog-gateway
  profiles:
    active: dev
  main:
    allow-bean-definition-overriding: true
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
      config:
        server-addr: 127.0.0.1:8848
        file-extension: yml
        shared-dataids: application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
    sentinel:
      eager: true
      transport:
        dashboard: 127.0.0.1:8718
      datasource:
        ds1:
          nacos:
            server-addr: 127.0.0.1:8848
            dataId: sentinel-eqics-gateway
            groupId: DEFAULT_GROUP
            data-type: json
            rule-type: flow

These are the two key profiles for my SpringCloud Gateway。

spencergibb commented 4 years ago

How do you make requests? What is the error or behavior you are seeing?

developers-youcong commented 4 years ago

My configuration in Nginx is as follows:

`

location /{

The proxy http://127.0.0.1:8080;

}

`

Result: Normal proxy, can access to the correct URL.

But if I configure it this way:

`

location /blog{

The proxy http://127.0.0.1:8080;

}

`

Result: Agent failed, access 404

developers-youcong commented 4 years ago

So I wonder if the gateway conflicts with Nginx

spencergibb commented 4 years ago

I'm sorry but nginx configuration isn't helpful.

developers-youcong commented 4 years ago

The error I saw was that it could not be accessed through the nginx reverse proxy.

If it is a separate gateway, not through Nginx, then normal.

developers-youcong commented 4 years ago

There is no specific error message

developers-youcong commented 4 years ago

I simply want to proxy the gateway project under Nginx and specify the access address.

Such as visiting http://127.0.0.1:8686/blog asked gateway

spencergibb commented 4 years ago

In the absence of anything that suggests there's a bug in gateway I'm going to close this.