0

假设我们有一个使用 Django 构建的 Web 应用程序,它使用命令“ docker-compose up”作为 docker 部署。现在我们已经部署并运行了 Web 应用程序。

18b01238718d   app_test:latest   "/app/entrypoints/ap…"   5 minutes ago   Up 5 minutes (healthy)   8001/tcp, 0.0.0.0:8002->8002/tcp   test_api
2b8f3b48d1e4   app_test:latest   "/app/entrypoints/cr…"   5 minutes ago   Up 5 minutes             8001-8002/tcp                      test_cron
a2413139919e   app_test:latest   "/app/entrypoints/ad…"   5 minutes ago   Up 5 minutes (healthy)   0.0.0.0:8001->8001/tcp, 8002/tcp   test_admin
4e76dbee107d   postgres:12.5     "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes             5432/tcp                           test_db

我们可以使用 IP:8001 访问该站点

我们如何使用 caddy 以 IP:80 访问该站点?

我做了什么:

install Caddy and verified it is running.

systemctl status caddy
● caddy.service - Caddy
   Loaded: loaded (/usr/lib/systemd/system/caddy.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2021-04-03 13:54:11 UTC; 3s ago

当访问 mydomain:80 时

您的网络服务器正在工作。现在让它为你工作。

Caddy is ready to serve your site over HTTPS:

Point your domain's A/AAAA DNS records at this machine.
Upload your site's files to /var/www/html.
Edit your Caddyfile at /etc/caddy/Caddyfile:
Replace :80 with your domain name
Change the site root to /var/www/html
Reload the configuration: systemctl reload caddy
Visit your site!

然后,我编辑了 /etc/caddy/Caddyfile: 如下

mydomain.com

# Set this path to your site's directory.
root * /usr/share/caddy  (I believe this should point to my volume of my docker web app. but I don't know how we can do that. any help is appreciated.   )

# Enable the static file server.
file_server

# Another common task is to set up a reverse proxy:
# reverse_proxy localhost:8080

# Or serve a PHP site through php-fpm:
# php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile
  www.mydonmain.com {
    reverse_proxy 127.0.0.1:8001
}

api.mydonmain.com {
    reverse_proxy 127.0.0.1:8002
}          
   

root * /usr/share/caddy
(我相信这应该指向我的 docker web 应用程序的卷。但我不知道我们如何做到这一点,因为 web 应用程序是使用 docker-compose 卷“运行”的。任何帮助表示赞赏。)

我的追求在哪里 systemctl status caddy

Apr 03 15:05:34 web-centos caddy[54954]: {"level":"info","ts":1617462334.6150506,"logger":"tls.issuance.acme","msg":"done waiting on internal rate limiter","identifiers":["mydomain.com"]}
Apr 03 15:05:34 web-centos caddy[54954]: {"level":"info","ts":1617462334.8799675,"logger":"tls.issuance.acme.acme_client","msg":"trying to solve challenge","identifier":"mydomain.com","challenge_type":"tl>
Apr 03 15:05:35 web-centos caddy[54954]: {"level":"info","ts":1617462335.2093322,"logger":"tls","msg":"served key authentication certificate","server_name":"mydomain.com","challenge":"tls-alpn-01","remote>
Apr 03 15:05:35 web-centos caddy[54954]: {"level":"info","ts":1617462335.286796,"logger":"tls","msg":"served key authentication certificate","server_name":"mydomain.com","challenge":"tls-alpn-01","remote">
Apr 03 15:05:35 web-centos caddy[54954]: {"level":"info","ts":1617462335.3579297,"logger":"tls","msg":"served key authentication certificate","server_name":"mydomain.com","challenge":"tls-alpn-01","remote>
Apr 03 15:05:35 web-centos caddy[54954]: {"level":"info","ts":1617462335.4760425,"logger":"tls","msg":"served key authentication certificate","server_name":"mydomain.com","challenge":"tls-alpn-01","remote>
4

0 回答 0