You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置JHipster微服务向注册中心注册自定义域名

Solution: Register JHipster UAA and Microservice with Custom Domains in Production

JHipster relies on Spring Cloud Netflix Eureka (via the JHipster Registry) for service discovery. To get UAA and Microservice1 to register with your custom domains instead of IP addresses, follow these step-by-step instructions:

Step 1: Set Up DNS Records First

Before modifying any service configurations, ensure your production DNS has A records pointing:

  • uaa.myapp.com → IP address of the server running UAA
  • microservice1.myapp.com → IP address of the server running Microservice1

Verify all services (Registry, Gateway, UAA, Microservice1) can resolve these hostnames using ping uaa.myapp.com and ping microservice1.myapp.com from each server.

Step 2: Configure UAA for Custom Domain Registration

Open the UAA service's src/main/resources/config/application-prod.yml file and update the Eureka instance settings:

eureka:
  instance:
    # Set UAA's custom hostname
    hostname: uaa.myapp.com
    # Disable IP address preference to use the hostname instead
    prefer-ip-address: false
    # Optional: Create a clear instance ID for easier Registry identification
    instance-id: ${eureka.instance.hostname}:${server.port}
  client:
    service-url:
      # Point to your JHipster Registry's domain (replace with your actual credentials/domain)
      defaultZone: http://your-registry-user:your-registry-pass@jhipster-registry.myapp.com:8761/eureka/

# Optional: Add HTTPS config if using SSL in production
server:
  port: 443
  ssl:
    enabled: true
    key-store-type: PKCS12
    key-store: classpath:keystore/uaa.myapp.com.p12
    key-store-password: your-keystore-pass
    key-alias: uaa.myapp.com

# Update UAA's issuer URI to use the custom domain (critical for OAuth2 token validation)
spring:
  security:
    oauth2:
      authorizationserver:
        issuer: https://uaa.myapp.com/uaa

Step 3: Configure Microservice1 for Custom Domain Registration

Repeat the same logic for Microservice1 in its src/main/resources/config/application-prod.yml:

eureka:
  instance:
    hostname: microservice1.myapp.com
    prefer-ip-address: false
    instance-id: ${eureka.instance.hostname}:${server.port}
  client:
    service-url:
      defaultZone: http://your-registry-user:your-registry-pass@jhipster-registry.myapp.com:8761/eureka/

# Optional: Add HTTPS config if using SSL
server:
  port: 443
  ssl:
    enabled: true
    key-store-type: PKCS12
    key-store: classpath:keystore/microservice1.myapp.com.p12
    key-store-password: your-keystore-pass
    key-alias: microservice1.myapp.com

Step 4: Update Gateway Configuration (Critical for Inter-Service Communication)

To ensure the Gateway can communicate with UAA using its custom domain, update the Gateway's application-prod.yml:

jhipster:
  security:
    oauth2:
      client:
        provider:
          oidc:
            # Point to UAA's custom domain for token validation
            issuer-uri: https://uaa.myapp.com/uaa

Step 5: Start Services with the Production Profile

Launch each service with the production profile activated to apply your config changes:

  • UAA:
    java -jar uaa-<your-version>.jar --spring.profiles.active=prod
    
  • Microservice1:
    java -jar microservice1-<your-version>.jar --spring.profiles.active=prod
    

Step 6: Verify Registration

Access your JHipster Registry UI (e.g., https://jhipster-registry.myapp.com:8761) and navigate to the Instances page. You should see:

  • UAA registered with hostname uaa.myapp.com
  • Microservice1 registered with hostname microservice1.myapp.com

Additional Notes

  • Firewall Rules: Ensure ports 8761 (Registry), your service ports (e.g., 8080 or 443), and OAuth2 ports are open between all services.
  • Registry Security: Replace the default admin/admin credentials in the Registry's config with strong production credentials.
  • Certificate Management: If using HTTPS, ensure all SSL certificates are valid and trusted across your infrastructure.

内容的提问来源于stack exchange,提问作者Colas Pomiès

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:59:04