MY WEBCAM TEST GUIDE

How to Run a Simple HTTPS Server on Linux

Run a simple HTTPS server on Linux to test camera and microphone pages: create a certificate, start a small Python server, and check that the browser treats the page as secure.

The short answer

On most Linux systems you can do this with two tools that are often already installed: OpenSSL to create a certificate, and Python 3 to serve files over HTTPS. Create a self-signed certificate and private key, then run a short Python script that wraps Python's built-in file server in TLS (the encryption layer behind HTTPS). The steps are below.

First, check whether you need HTTPS at all. Browsers allow camera and microphone access only in a secure context. A secure context is a page loaded over HTTPS or from your own machine through localhost. If you open your test page in a browser on the same computer through localhost, a plain HTTP server is usually enough. HTTPS matters when you open the page from another device, such as a phone or a second laptop, through your computer's network address. Without HTTPS, the browser will not show a camera or microphone permission prompt.

Step 1: Create a certificate and key

Open a terminal in the folder that holds the files you want to serve. Run this command to create a self-signed certificate (cert.pem) and its private key (key.pem). Self-signed means you vouch for the certificate yourself instead of a recognized certificate authority. The -days value sets how long the certificate stays valid, and you can change it.

openssl req -x509 -newkey rsa:2048 -nodes \
  -keyout key.pem -out cert.pem -days 30 \
  -subj "/CN=localhost" \
  -addext "subjectAltName=DNS:localhost,IP:YOUR_LAN_IP"

Replace YOUR_LAN_IP with your computer's local network IP address. You can find it with the command ip addr or hostname -I. This line lets the certificate match the address other devices will use. If you only test on the same machine, you can leave out the -addext line. The -addext option needs a reasonably recent version of OpenSSL. If your version rejects it, update OpenSSL or use the mkcert approach described below.

Step 2: Start the HTTPS server

Save the following as https_server.py in the same folder as the certificate files. Then run it with python3 https_server.py.

import http.server
import ssl

server = http.server.HTTPServer(("", 8443), http.server.SimpleHTTPRequestHandler)

context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile="cert.pem", keyfile="key.pem")
server.socket = context.wrap_socket(server.socket, server_side=True)

print("Serving HTTPS on port 8443")
server.serve_forever()

The empty string tells the server to listen on all network interfaces, so other devices on your network can reach it. Port 8443 is used because ports below 1024 need root privileges on Linux. Press Ctrl+C in the terminal to stop the server.

Step 3: Open the page and verify the result

  • In the browser, type https followed by your computer's IP address (or localhost on the same machine), a colon, 8443, and the file name if needed.
  • Expect a certificate warning. The browser does not recognize a self-signed certificate. For your own test server, you can choose the option to continue anyway.
  • If the page does not load from another device, check the firewall. With ufw, for example, sudo ufw allow 8443/tcp opens the port.
  • On a page that requests the camera or microphone, a permission prompt should now appear. In the browser's developer console, the expression window.isSecureContext should return true.

A permission prompt only shows that the browser now allows the page to ask for access. It does not prove the camera delivers a picture or the microphone picks up sound. Check those separately: look for a live video preview, a moving input level, and audio that is clear on playback. How well a call performs is a separate question again.

Avoiding the certificate warning

If the warning gets in the way, especially on phones, a tool such as mkcert can help. mkcert creates a small local certificate authority and issues certificates that your own machine trusts. Other devices trust these certificates only if you install that authority's root certificate on them. Install it only on devices you control, and keep the authority's files private.

Limitations and safety notes

  • This setup is for local testing only, not for public hosting.
  • The server shares every file in the folder where you start it and in its subfolders. Run it from a dedicated folder, not your home directory.
  • Keep key.pem private, and delete the files once you finish testing.
  • Python's built-in server is basic. It handles simple static pages, not heavy traffic.

This guide does not cover how individual browser versions or mobile operating systems handle self-signed certificates. No specific evidence on that was available, so expect the exact warning screens and the steps to bypass them to vary.