> For the complete documentation index, see [llms.txt](https://gitbook.gpg123.vip/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.gpg123.vip/traefik-yi-ge-qiang-da-de-dai-li-pei-zhi-gong-ju/ji-yu-wen-jian/shi-jian-an-li.md).

# 实践案例

## 准备环境

* [x] 拥有一个域名
* [x] 域名解析到服务器ip
* [x] 自有ssl或开启ACME 自动生成HTTPS证书

## http/https

{% code title="" %}

```
http:
  routers:
    home-router:
      entryPoints:
        - http
        - https
```

{% endcode %}

## router

{% code title="" %}

```
routers:
  home-router:
    entryPoints:
      - http
      - https
```

{% endcode %}

## middleware

{% code title="" fullWidth="false" %}

```yaml
#中间件
middlewares:
  home-middleware:
    addPrefix:
      prefix: "/"
```

{% endcode %}

## service

{% code title="" %}

```yaml
services:
  # Define how to reach an existing service on our infrastructure
  home-service:
    loadBalancer:
      servers:
        - url: http://server.gpg123.vip:8081
```

{% endcode %}

## 完整文件：

{% code title="home.yml" %}

```yaml
http:
  routers:
    home-router:
      entryPoints:
        - http
        - https
      middlewares:
        - home-middleware
      service: home-service
      rule: "Host(`gpg123.vip`) && PathPrefix(`/`)"
      tls:
        certResolver: "myCertResolver"
  #中间件
  middlewares:
    home-middleware:
      addPrefix:
        prefix: "/"
  services:
    # Define how to reach an existing service on our infrastructure
    home-service:
      loadBalancer:
        servers:
          - url: http://server.gpg123.vip:8081
```

{% endcode %}

更新到traefik配置文件目录

<figure><img src="https://1477494011-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjENyhayFBE8frwWaXFeM%2Fuploads%2FkSBvxzGxwzEMS6CJblzU%2Fimage.png?alt=media&amp;token=261c80cd-70b6-49ba-8a37-6f9e078ff477" alt=""><figcaption></figcaption></figure>
