Can't connect Caddy v1.0.4 and Ubuntu 19.10, Apache2, localhost

Problem:

Unable to get Caddy and Apache2 Servers to work together. They work separately and I have tried numerous suggestions and would be very grateful for a solution.

Meanwhile to simplify switching, restarting, checking status, etc I created a PHP menu system with access the following setup:

file: /etc/apache2/sites-available/amum.tk.conf

# 2019-12-10
<VirtualHost *:80>
  ServerName amum.tk 
  # ServerName apop.tk 
  DocumentRoot /var/www/amum.tk/public_html
  <Directory /var/www/amum.tk/public_html/>
    DirectoryIndex index.php index.html home.html
    Options +Indexes +FollowSymlinks +MultiViews
    AllowOverride all
    Require all granted      
  </Directory>
  ErrorLog  ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

file: /etc/hosts

# DOES NOT REQUIRE systemctl reload apache2
127.0.0.1 localhost
127.0.1.1 amum.tk
127.0.1.1 apop.tk

file: /etc/caddy/Caddyfile

amum.tk, 
apop.tk
{
  tls off
  # gzip
  proxy / localhost:2015
  {
    # transparent
  }
  log    /var/log/apache2/caddy/caddy-access.log
  errors /var/log/apache2/caddy/caddy-errors.log
}

Following logging OK

  file: /var/log/apache2/access.log
  file: /var/log/apache2/errors.log
  file: /var/log/apache2/caddy/caddy-access.log
  file: /var/log/apache2/caddy/caddy-errors.log

systemctl status caddy

â—Ź caddy.service - Caddy HTTP/2 web server
   Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-12-12 11:27:15 +07; 15s ago
     Docs: https://caddyserver.com/docs
 Main PID: 8611 (caddy)
    Tasks: 10 (limit: 4915)
   Memory: 2.1M
   CGroup: /system.slice/caddy.service
           └─8611 /usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp

Dec 12 11:27:15 john systemd[1]: Started Caddy HTTP/2 web server.
Dec 12 11:27:15 john caddy[8611]: 2019/12/12 11:27:15 [INFO] Caddy version: v1.0.4
Dec 12 11:27:15 john caddy[8611]: Activating privacy features... done.
Dec 12 11:27:15 john caddy[8611]: 2019/12/12 11:27:15 [INFO][cache:0xc0001c2190] Started certificate maintenance routine
Dec 12 11:27:15 john caddy[8611]: Serving HTTP on port 2015
Dec 12 11:27:15 john caddy[8611]: http://amum.tk:2015
Dec 12 11:27:15 john caddy[8611]: http://apop.tk:2015
Dec 12 11:27:15 john caddy[8611]: 2019/12/12 11:27:15 [INFO] Serving http://amum.tk:2015
Dec 12 11:27:15 john caddy[8611]: 2019/12/12 11:27:15 [INFO] Serving http://apop.tk:2015

Hi @John_Betong, welcome to the Caddy community.

Just a quick question, it looks like in Apache your virtual host is defined to listen on port 80, but Caddy is proxying back to localhost port 2015. Is this accurate? Is there something in the middle translating that traffic where it needs to go?

Actually, after looking a bit closer, it looks like Caddy is starting up and listening on port 2015 as well, as you’ve disabled Automatic HTTPS. So I think it’d be proxying to itself…?

What, exactly, is the setup you want to achieve? Client → Caddy → Apache → PHP?

At the moment I am using a Linode VPS with Ubuntu and Apache2 to run over a dozen PHP and MySqli driven sites.

I would like a Caddy server to run alongside so I can experiment with Golang. All I want at the moment is a simple “Hello-world.html” web page. Later, php, etc

Apache2 users ports 80, 443 and another for MySqli.

Do this:

amum.tk:8080, 
apop.tk:8080
{
  tls off
  log    /var/log/caddy/caddy-access.log
  errors /var/log/caddy/caddy-errors.log
}

Make sure /var/log/caddy exist with proper permissions. That will run caddy on 8080 for those two domains, tls off.

@Fastidious, many thanks for the reply.

Browsing to: http://amum.tk:8080 renders /var/www/amum.tk/public_html/index.html
on the Golang Server.

and

browsing to http://amum.tk renders /var/www/amum.tk/public_html/index.php
on the Apache2 Server.

What I would like is to be able to browse to: http://amum.tk and render
/var/www/amum.tk/public_html/index.html
on the Golang Server.

Is it necessary to use proxy, redir or other commands to achieve the desired result?

You need to set your mind on which server you want to use which ports, they can’t use the same port.

If you want caddy to use 80 you will need to change apache’s port to something else. Then you can proxy to it using caddy.

So, assuming you change apache to listen on 8080, then the Caddyfile should be:

# This one will proxy to apache on port 8080.
apup.tk {
  tls off
  log    /var/log/caddy/caddy-apup-tk-access.log
  errors /var/log/caddy/caddy-apup-tk-errors.log
  proxy / http://127.0.0.1:8080 {
        transparent
  }
}

# This will just serve amum.tk on port 80.
amum.tk {
  root /path/to/root/www
  tls off
  log    /var/log/caddy/caddy-amum-tk-access.log
  errors /var/log/caddy/caddy-amum-tk-errors.log
}

1 Like

Is it possible to have Apache2 use port:80 and also to install Caddy so that browsing to http://anum.tk would render correctly?

Currently I have 15 Apache2 sites and it would be a lot of work to change the port to 8080

I did try and corrupt my Ubuntu system and need a reinstall :frowning:

The default HTTP port is 80. Trying to run Caddy on default HTTP(S) ports (80 and 443) but have Apache on port 80 is fundamentally impossible. Apache and Caddy cannot share the port. You must decide which one you want to use that port.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.