csdn_sqj
2020-01-10 10:05
采纳率: 60.3%
浏览 1.3k
已采纳

紧急求助!springcloud:为什么我的zuul配置的路由没有生效?

图片说明
+++++++++++++
图片说明
图片说明
+++++++++++++
我在网关模块做了一下配置
zuul:
prefix: /api
routes:
item-service: /item/** #路由到商品的微服务

图片说明
++++++++++++
nginx的配置

#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;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;

    server {
        listen       80;
        server_name  manage.leyou.com;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
             proxy_pass http://127.0.0.1:9001;
             proxy_connect_timeout 600;
             proxy_read_timeout 600;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    server {
        listen       80;
        server_name  api.leyou.com;

        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        location / {
             proxy_pass http://127.0.0.1:9001;
             proxy_connect_timeout 600;
             proxy_read_timeout 600;
        }
    }
}

+++++++++
前端页面端口:9001
商品模块端口:8081
网关端口:10010
eureka端口:10086
|
我明明在网关里配置了api路由到item
为什么没有生效呢?
请大神指教,谢谢
++++++++++++++++++
更新
图片说明

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • 路漫漫兮其修远兮 2020-01-10 10:29
    已采纳

    你上面写的网管配置有问题,把截图放出来,也不知道你的yml格式对不对

    zuul:
      prefix: /api
      routes:
        item-service:
          path: /item/** #路由到商品的微服务
          service-id: item-service
    

    缺少path,一定要确认 item-service就是你的服务

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题