Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Production-Ready Setup: Apache + Laravel + Docker + Dynamic Reverse Proxy for Multiple Users

This updated guide explains how to implement a scalable, production-ready setup where each user gets a Docker container and unique subdomain like user123.wizbrand.com, without creating new Apache VirtualHosts for each.


โœ… 1. Apache Configuration (Dynamic Reverse Proxy)

Apache Modules (Enable Once)

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod rewrite
sudo systemctl restart apache2

Apache Wildcard VirtualHost (Single File)

Edit /opt/lampp/etc/extra/httpd-vhosts.conf or /etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
    ServerName wizbrand.com
    ServerAlias *.wizbrand.com

    ProxyPreserveHost On
    RewriteEngine On

    # Extract user ID from subdomain (e.g., user123)
    RewriteCond %{HTTP_HOST} ^user([0-9]+)\.wizbrand\.com$ [NC]
    RewriteRule ^/(.*)$ http://127.0.0.1:9%1/$1 [P,L]

    ProxyPassReverse / http://127.0.0.1/
</VirtualHost>
Code language: PHP (php)

Restart Apache:

sudo systemctl restart apache2

โœ… 2. Laravel Controller to Spawn Container and Return URL

Create ContainerController.php:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ContainerController extends Controller
{
    public function createUserContainer(Request $request)
    {
        $user = Auth::user();
        $containerName = 'user-' . $user->id;
        $port = 9000 + $user->id;

        // Start Docker container mapped to unique port
        shell_exec("docker run -d -p {$port}:80 --name {$containerName} my-image");

        // Return container's unique URL
        return response()->json([
            'url' => "http://user{$user->id}.wizbrand.com"
        ]);
    }
}
Code language: PHP (php)

Add Laravel Route (routes/web.php)

Route::get('/create-container', [ContainerController::class, 'createUserContainer'])->middleware('auth');
Code language: PHP (php)

โœ… 3. Domain Setup (Production)

In your domain provider’s DNS (e.g., GoDaddy, Cloudflare), add:

TypeNameValue
A*your_server_ip

This wildcard allows user123.wizbrand.com โ†’ your server.


โœ… 4. Local Testing Setup

Add to /etc/hosts (on dev machine)

127.0.0.1 user123.wizbrand.com
127.0.0.1 user456.wizbrand.com
Code language: CSS (css)

Or use:

  • nip.io: user123.127.0.0.1.nip.io
  • sslip.io: user123.127.0.0.1.sslip.io

โœ… 5. Docker Image Assumptions

  • Exposes port 80
  • Named my-image or configured dynamically

Example container:

docker run -d -p 9123:80 --name user-123 my-image
Code language: CSS (css)

โœ… 6. Test Script (Optional Bash)

#!/bin/bash
USER_ID=$1
PORT=$((9000 + USER_ID))
CONTAINER="user-${USER_ID}"

# Launch container
sudo docker run -d -p ${PORT}:80 --name ${CONTAINER} my-image

# Access URL
echo "Container for user ${USER_ID} available at: http://user${USER_ID}.wizbrand.com"
Code language: PHP (php)

Usage:

./create-container.sh 123

๐Ÿง  Summary

ComponentRole
Apache (Wildcard)Dynamic proxy via subdomain-to-port
LaravelContainer creator & subdomain router
DockerUser-specific environments
DNS (Wildcard)Resolves all subdomains to one IP

This approach is clean, scalable, reload-free, and requires just one Apache config regardless of user count. Let me know if you’d like to add Let’s Encrypt SSL automation, container auto-cleanup, or database tracking next.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Hereโ€™s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories…

Read More

Docker Tutorials: Installation and Configurations

Docker Installation in Centos/RHEL Method -1: How to install Docker Community Edition via YUM? Step 1 – Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data…

Read More

Docker Tutorials: How to Install Docker in Ubuntu?

Install Docker Engine in Ubuntu NOTE – All commands you must run as root user or add a current user into a linux group name called “docker”…

Read More

Docker Lab, Excercise & Assignment – 7 – Docker Volume

Below is a very detailed tutorial and lab manual for learning Docker Volumes, using the Ubuntu image for practical, hands-on labs. This covers all major types of…

Read More

Docker Lab, Excercise & Assignment – 4 – Docker Networking

Hereโ€™s an in-depth, step-by-step tutorial and lab manual for Docker Networkingโ€”starting from basics, covering all core concepts, and providing a hands-on guide to every feature and command….

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x