@@ -111,6 +111,53 @@ if [ -f "${SCRIPT_DIR}/Dockerfile" ]; then
111111 BUILD_FROM_SOURCE=" true"
112112fi
113113
114+ # When a domain is set, check if ports 80/443 are available
115+ PROXY_MODE=" direct" # direct = Caddy handles TLS on 80/443, external = user's proxy handles TLS
116+ if [ -n " $DOMAIN_NAME " ]; then
117+ PORT_80_FREE=true
118+ PORT_443_FREE=true
119+ if ss -tlnp 2> /dev/null | grep -q ' :80 ' || netstat -tlnp 2> /dev/null | grep -q ' :80 ' ; then
120+ PORT_80_FREE=false
121+ fi
122+ if ss -tlnp 2> /dev/null | grep -q ' :443 ' || netstat -tlnp 2> /dev/null | grep -q ' :443 ' ; then
123+ PORT_443_FREE=false
124+ fi
125+
126+ if [ " $PORT_80_FREE " = " false" ] || [ " $PORT_443_FREE " = " false" ]; then
127+ echo " "
128+ echo -e " ${YELLOW} Port 80 and/or 443 are already in use.${NC} "
129+ echo -e " Another service (nginx, Traefik, Apache, etc.) is using these ports."
130+ echo " "
131+
132+ if [ " $NON_INTERACTIVE " = " true" ]; then
133+ PROXY_MODE=" external"
134+ else
135+ echo -e " Choose how to handle HTTPS for ${GREEN}${DOMAIN_NAME}${NC} :"
136+ echo " "
137+ echo -e " ${GREEN} 1)${NC} External proxy mode (recommended)"
138+ echo -e " Multi-PB stays on port ${MULTIPB_PORT} (HTTP only)."
139+ echo -e " Configure your existing proxy to forward ${DOMAIN_NAME} → localhost:${MULTIPB_PORT} "
140+ echo " "
141+ echo -e " ${GREEN} 2)${NC} Free ports 80/443 and let Multi-PB handle TLS"
142+ echo -e " You'll need to stop the service using these ports first."
143+ echo " "
144+ read -p " Choice [1]: " PROXY_CHOICE
145+ PROXY_CHOICE=" ${PROXY_CHOICE:- 1} "
146+ if [ " $PROXY_CHOICE " = " 2" ]; then
147+ echo " "
148+ echo -e " ${YELLOW} Please free ports 80 and 443, then re-run the installer.${NC} "
149+ exit 0
150+ fi
151+ PROXY_MODE=" external"
152+ fi
153+
154+ if [ " $PROXY_MODE " = " external" ]; then
155+ echo -e " ${GREEN} Using external proxy mode.${NC} "
156+ echo -e " Multi-PB will run on port ${MULTIPB_PORT} (HTTP). Your existing proxy handles TLS."
157+ fi
158+ fi
159+ fi
160+
114161echo " "
115162echo -e " ${YELLOW} Creating configuration...${NC} "
116163
@@ -147,8 +194,8 @@ cat >> "$INSTALL_DIR/docker-compose.yml" << EOF
147194 - "${MULTIPB_PORT} :25983"
148195EOF
149196
150- # Add optional ports and env vars
151- if [ -n " $DOMAIN_NAME " ]; then
197+ # Only expose 80/443 if domain is set AND we're in direct mode (Caddy handles TLS)
198+ if [ -n " $DOMAIN_NAME " ] && [ " $PROXY_MODE " = " direct " ] ; then
152199cat >> " $INSTALL_DIR /docker-compose.yml" << EOF
153200 - "80:80"
154201 - "443:443"
@@ -163,8 +210,9 @@ cat >> "$INSTALL_DIR/docker-compose.yml" << EOF
163210 - MULTIPB_DATA_DIR=/var/multipb/data
164211EOF
165212
166- # Add domain env var only if set
167- if [ -n " $DOMAIN_NAME " ]; then
213+ # Set MULTIPB_DOMAIN only in direct mode (Caddy handles TLS)
214+ # In external proxy mode, Caddy stays HTTP-only on :25983
215+ if [ -n " $DOMAIN_NAME " ] && [ " $PROXY_MODE " = " direct" ]; then
168216cat >> " $INSTALL_DIR /docker-compose.yml" << EOF
169217 - MULTIPB_DOMAIN=${DOMAIN_NAME}
170218EOF
@@ -188,6 +236,14 @@ echo "━━━━━━━━━━━━━━━━━━━━━━━━
188236echo -e " Container: ${GREEN}${CONTAINER_NAME}${NC} "
189237echo -e " Port: ${GREEN} http://localhost:${MULTIPB_PORT}${NC} "
190238echo -e " Data Dir: ${GREEN}${DATA_DIR}${NC} "
239+ if [ -n " $DOMAIN_NAME " ]; then
240+ echo -e " Domain: ${GREEN}${DOMAIN_NAME}${NC} "
241+ if [ " $PROXY_MODE " = " external" ]; then
242+ echo -e " TLS: ${YELLOW} External proxy (configure your proxy → localhost:${MULTIPB_PORT} )${NC} "
243+ else
244+ echo -e " TLS: ${GREEN} Caddy (automatic HTTPS on ports 80/443)${NC} "
245+ fi
246+ fi
191247if [ " $CLI_ONLY " = " true" ]; then
192248 echo -e " Mode: ${YELLOW} CLI-only (no dashboard)${NC} "
193249fi
@@ -246,6 +302,42 @@ if [[ ! "$START_NOW" =~ ^[Nn]$ ]]; then
246302 echo -e " ${BLUE} docker exec ${CONTAINER_NAME} remove-instance.sh myapp${NC} "
247303 echo " "
248304
305+ # Show external proxy instructions if applicable
306+ if [ -n " $DOMAIN_NAME " ] && [ " $PROXY_MODE " = " external" ]; then
307+ echo " "
308+ echo -e " ${YELLOW} ━━━ External Proxy Setup ━━━${NC} "
309+ echo -e " Configure your reverse proxy to forward ${GREEN}${DOMAIN_NAME}${NC} to ${GREEN} localhost:${MULTIPB_PORT}${NC} "
310+ echo " "
311+ echo -e " ${BLUE} Nginx example:${NC} "
312+ echo " server {"
313+ echo " listen 80;"
314+ echo " server_name ${DOMAIN_NAME} ;"
315+ echo " location / {"
316+ echo " proxy_pass http://127.0.0.1:${MULTIPB_PORT} ;"
317+ echo " proxy_set_header Host \$ host;"
318+ echo " proxy_set_header X-Real-IP \$ remote_addr;"
319+ echo " proxy_set_header X-Forwarded-For \$ proxy_add_x_forwarded_for;"
320+ echo " proxy_set_header X-Forwarded-Proto \$ scheme;"
321+ echo " }"
322+ echo " }"
323+ echo " "
324+ echo -e " ${BLUE} Caddy example:${NC} "
325+ echo " ${DOMAIN_NAME} {"
326+ echo " reverse_proxy localhost:${MULTIPB_PORT} "
327+ echo " }"
328+ echo " "
329+ echo -e " ${BLUE} Traefik (docker labels):${NC} "
330+ echo " Add to your docker-compose.yml under ${CONTAINER_NAME} :"
331+ echo " labels:"
332+ echo " - traefik.enable=true"
333+ echo " - traefik.http.routers.multipb.rule=Host(\` ${DOMAIN_NAME} \` )"
334+ echo " - traefik.http.services.multipb.loadbalancer.server.port=25983"
335+ echo " "
336+ echo -e " After configuring your proxy, ${GREEN}${DOMAIN_NAME}${NC} will serve Multi-PB."
337+ echo -e " Your proxy handles TLS — add HTTPS there (e.g. certbot for nginx, automatic for Caddy/Traefik)."
338+ echo " "
339+ fi
340+
249341 # Try to open browser (skip dashboard in CLI-only mode)
250342 if [ " $CLI_ONLY " != " true" ]; then
251343 if command -v xdg-open & > /dev/null; then
0 commit comments