"Can't connect to the server" for local dev using self signed cert

I am developing a payment application that requires a secure connection so I am using the following for local development:

config :app_web, AppWeb.Endpoint,
  https: [
    port: 4001,
    cipher_suite: :strong,
    keyfile: "priv/cert/selfsigned_key.pem",
    certfile: "priv/cert/selfsigned.pem"
  ]

The application starts fine but when I attempt to load the application in Safari I see “Safari Can’t connect to the server” in bold followed by “Safari can’t open the page “https://dev.localhost:4001” because Safari can’t connect to the server “dev.localhost””. I have mapped 127.0.0.1 in my host such that dev.localhost should resolve and it does for a non-secure (http) request using post 4000. The certs are present as I have run mix phx.gen.cert. Chrome also does not load the site and displays:

This site can’t be reached
**dev.localhost** refused to connect.

My OS is macOS Big Sur and Safari version is 14.0.2. Any help would be great.

Have you checked using netstat/ss if your application actually listens on 4001?

How do you start the app? As a release or via mix phx.server? If the former, have you server: true in your endpoint config?

Also of course check your servers logs on “boot”.

1 Like

Nothing is listening on 4001. This pointed me to the docker-compose file and it did not have port 4001 mapped. Adding the last line and it now works:

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "4000:4000"
      - "4001:4001"

Thanks and sorry to waste your time.

1 Like