Express网关无法访问API,无法绑定nginx代理,服务器响应:无法获取

pbpqsu0x  于 7个月前  发布在  Nginx
关注(0)|答案(1)|浏览(73)

我有一些连接到Express网关的微服务服务器,网关在本地工作正常,但在服务器内部,它无法访问其他API路由,例如,如果我尝试获取http://xx.xx.xx.xx/api-docs,它会响应“cannot get /api-docs”或任何其他路由,但当我在本地尝试http://localhost:4010/api-docs时,它工作正常。
服务器规格为Linux ubunto 20,nginx 1.18.0,node v18.17.1
下面是我的yaml配置文件,URL位于.env文件中,它是这样的:SWAGGER_DB=http://localhost:4006

http:
  port: ${PORT}
  hostname: 0.0.0.0
admin:
  port: 9876
  host: localhost
apiEndpoints:
  auth:
    host: localhost
    paths: ['/users*', '/auth*', '/admin*']
  catalog:
    host: localhost
    paths: ['/products*', '/tags*', '/sizes*', '/categories*', '/brands*', '/colors*', '/parameters*']
  images:
    host: localhost
    paths: ['/images*']
  orders:
    host: localhost
    paths: ['/addresses*', '/baskets*', '/checkouts*', '/order-products*', '/payments*']
  reviews:
    host: localhost
    paths: ['/reviews*', '/comments*']
  questions:
    host: localhost
    paths: ['/questions*', '/question-comments*']
  swagger:
    host: localhost
    paths: ['/api-docs*']
  wishlists:
    host: localhost
    paths: ['/wishlists*']
  banners:
    host: localhost
    paths: ['/slides*', '/advertisements*']
  analytics:
    host: localhost
    paths: ['/analytics*']
  mailer:
    host: localhost
    paths: ['/subscribe*', '/mailings*']
serviceEndpoints:
  authSrv:
    url: ${AUTH_DB}
  catalogSrv:
    url: ${CATALOG_DB}
  imagesSrv:
    url: ${IMAGES_DB}
  ordersSrv:
    url: ${ORDERS_DB}
  reviewsSrv:
    url: ${REVIEWS_DB}
  questionsSrv:
    url: ${QUESTIONS_DB}
  swaggerSrv:
    url: ${SWAGGER_DB}
  wishlistsSrv:
    url: ${WISHLISTS_DB}
  bannersSrv:
    url: ${BANNERS_DB}
  analyticsSrv:
    url: ${ANALYTICS_DB}
  mailerSrv:
    url: ${MAILER_DB}
policies:
  - cors
  - proxy
pipelines:
  pipeAuth:
    apiEndpoints:
      - auth
    policies:
      - proxy:
          - action:
              serviceEndpoint: authSrv
              changeOrigin: true
  pipeCatalog:
    apiEndpoints:
      - catalog
    policies:
      - proxy:
          - action:
              serviceEndpoint: catalogSrv
              changeOrigin: true
  pipeImages:
    apiEndpoints:
      - images
    policies:
      - proxy:
          - action:
              serviceEndpoint: imagesSrv
              changeOrigin: true
  pipeOrders:
    apiEndpoints:
      - orders
    policies:
      - proxy:
          - action:
              serviceEndpoint: ordersSrv
              changeOrigin: true
  pipeReviews:
    apiEndpoints:
      - reviews
    policies:
      - proxy:
          - action:
              serviceEndpoint: reviewsSrv
              changeOrigin: true
  pipeQuestions:
    apiEndpoints:
      - questions
    policies:
      - proxy:
          - action:
              serviceEndpoint: questionsSrv
              changeOrigin: true
  pipeSwagger:
    apiEndpoints:
      - swagger
    policies:
      - proxy:
          - action:
              serviceEndpoint: swaggerSrv
              changeOrigin: true
  pipeWishlists:
    apiEndpoints:
      - wishlists
    policies:
      - proxy:
          - action:
              serviceEndpoint: wishlistsSrv
              changeOrigin: true
  pipeBanner:
    apiEndpoints:
      - banners
    policies:
      - proxy:
          - action:
              serviceEndpoint: bannersSrv
              changeOrigin: true
  pipeAnalytic:
    apiEndpoints:
      - analytics
    policies:
      - proxy:
          - action:
              serviceEndpoint: analyticsSrv
              changeOrigin: true
  pipeMailer:
    apiEndpoints:
      - mailer
    policies:
      - proxy:
          - action:
              serviceEndpoint: mailerSrv
              changeOrigin: true

字符串
使用Nginx的反向代理

server {
    server_name xx.xxx.xxx.183; // here is the server ip address

    location / {
        proxy_pass http://localhost:4010;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}


我尝试了这个解决方案,但没有结果How to bind express-gateway

pbgvytdp

pbgvytdp1#

问题是在apiEndpointshost我发现在快递网关文档here的sluotion,我只是不得不改变主机从localhost到我的服务器IP地址这样:

apiEndpoints:
  auth:
    host: 192.xxx.xxx.xxx //add your server ip address here
    paths: ['/users*', '/auth*', '/admin*']
  catalog:
    host: 192.xxx.xxx.xxx //add your server ip address here
    paths: ['/products*', '/tags*', '/sizes*', '/categories*', '/brands*', '/colors*', '/parameters*']
  images:
    host: 192.xxx.xxx.xxx //add your server ip address here
    paths: ['/images*']
.
.
.

字符串

相关问题