DEV Community

Cover image for How to Access Answer Using HTTPS
Apache Answer
Apache Answer

Posted on

How to Access Answer Using HTTPS

Background

When you already have a server, you may want to deploy Answer on it. After deploying Answer, you will realize that you can only access it using HTTP. However, you may want to access it using HTTPS. So how can you do that?

Some questions:

I found that many people have this question. Deploying Answer is easy, but deploying it with HTTPS is a bit difficult. So I decided to write this article to help you deploy Answer with HTTPS.

Easy way

This blog aims to introduce the easiest way to deploy Answer with HTTPS. You can use Caddy to deploy Answer with HTTPS. Caddy is a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go. Of course, you can use other tools to deploy Answer with HTTPS, such as Nginx, etc.

Preparation

  1. You can follow the installation guide to install Answer. After installing Answer, you can access it using HTTP. The default port for Answer is 9080. You can access it at http://localhost:9080. In the following steps, we will use 9080 as the default port for Answer.

  2. You need a domain that DNS resolution is already configured to point to your server.

  3. In this blog we will use docker-compose to install Caddy. So we need docker and docker-compose. You can follow the official guide to install docker and docker-compose.

Deploy

Step 1

$ mkdir caddy-docker
$ cd caddy-docker
$ vim docker-compose.yml
Enter fullscreen mode Exit fullscreen mode

You can create a docker-compose.yml file in the new directory, and then add the following code:

version: "3.7"

services:
  caddy:
    image: caddy
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - $PWD/caddy_data:/data
      - $PWD/caddy_config:/config
    network_mode: host
Enter fullscreen mode Exit fullscreen mode

Step 2

The Caddyfile is the configuration file for Caddy. It is used to configure how Caddy should serve your site. This file will be mounted into the container at /etc/caddy/Caddyfile.

$ vim Caddyfile
Enter fullscreen mode Exit fullscreen mode

Create Caddyfile file in the same directory, and then add the following code:

your.answer.domain {
    reverse_proxy 127.0.0.1:9080
}
Enter fullscreen mode Exit fullscreen mode

Step 3

Run the following command to start Caddy. Wait a few seconds, and then you can access Answer using HTTPS.

$ docker-compose up -d
Enter fullscreen mode Exit fullscreen mode

If you can't access it, you can check the logs of Caddy.

$ docker-compose logs
Enter fullscreen mode Exit fullscreen mode

Advanced

If you don't want to use network_mode: host in docker-compose.yml, you can put Answer and Caddy in the same docker compose. Then Caddy and Answer can use the same network. So you can configure Caddy like this:

your.answer.domain {
    reverse_proxy answer-service:9080
}
Enter fullscreen mode Exit fullscreen mode

Of course, you can also install Caddy using other methods, such as using the binary file, etc. All in all, I wish you can follow this blog to deploy Answer with HTTPS successfully. If you have any questions, please feel free to leave a question on Meta. We will try our best to help you.

Top comments (0)