Home › Developer Tools › Apache Virtual Host Generator

Apache Virtual Host Generator

Choose the kind of site, enter your domain and get a complete, commented Apache VirtualHost file. It handles HTTPS with Let's Encrypt or your own certificate, HTTP to HTTPS and www redirects, PHP-FPM, reverse proxying with WebSockets, single-page app routing, compression, caching and security headers, plus the exact commands for Debian/Ubuntu or RHEL-based servers.

Last updated:

Site
HTTPS
Performance & security
Redirects

Generated configuration

    Advertisement
    Advertisement

    How to use the Apache Virtual Host Generator

    1. Choose the site type: static files, PHP through PHP-FPM, a reverse proxy to an app server, or a single-page app.
    2. Enter ServerName and aliases, the document root or backend URL, and pick how www should be handled.
    3. Set up HTTPS with Let's Encrypt or your own certificate, and choose the HTTP to HTTPS redirect, HTTP/2 and HSTS.
    4. Pick performance and security options and add any custom redirects.
    5. Copy the config or the install commands, save the file, run the config test and reload Apache.

    How Apache chooses a virtual host

    For each request Apache first looks at the IP address and port, then at the host name:

    1. All <VirtualHost> blocks whose address and port match the connection (for example *:443) are candidates.
    2. Among them, the first one whose ServerName or ServerAlias matches the request's Host header wins.
    3. If no name matches, the first candidate in load order is used as the default. That is why the stock 000-default.conf often answers unknown names on Debian and Ubuntu.

    Modules used by the generated config

    ModuleNeeded forKey directives
    mod_sslHTTPSSSLEngine, SSLCertificateFile, SSLProtocol
    mod_http2HTTP/2Protocols h2 http/1.1
    mod_proxy + mod_proxy_httpReverse proxyProxyPass, ProxyPassReverse, ProxyPreserveHost
    mod_proxy_fcgiPHP-FPMSetHandler "proxy:unix:…|fcgi://localhost"
    mod_headersSecurity headers, HSTS, X-Forwarded-ProtoHeader always set, RequestHeader set
    mod_deflate + mod_filterCompressionAddOutputFilterByType DEFLATE
    mod_expiresBrowser cachingExpiresActive, ExpiresByType
    mod_dirSingle-page appsFallbackResource /index.html
    mod_aliasRedirectsRedirect, RedirectMatch

    Troubleshooting checklist

    • Always run the config test (apache2ctl configtest or apachectl configtest) and reload instead of restart so open connections are not dropped.
    • 403 Forbidden: the Apache user (www-data or apache) needs read access to the files and execute access to every parent folder, and the <Directory> block must contain Require all granted. On SELinux systems also check the file context with ls -Z.
    • 503 Service Unavailable behind a proxy: the backend is not running or listens elsewhere. Test it on the server with curl -I http://127.0.0.1:3000/ and read the site's error log.
    • PHP source is downloaded instead of run: the PHP handler is missing; check the PHP-FPM socket path with ls /run/php/ and that mod_proxy_fcgi is enabled.
    • Redirect loop behind Cloudflare or a load balancer: the proxy may talk to Apache over HTTP, so the HTTP to HTTPS redirect fires again. Use the proxy's own HTTPS redirect or full end-to-end TLS.

    Frequently asked questions

    Where do Apache virtual host files go?

    On Debian and Ubuntu, save the file in /etc/apache2/sites-available/ with a .conf extension and enable it with sudo a2ensite name.conf. On RHEL, Rocky, AlmaLinux and Fedora, put it in /etc/httpd/conf.d/ with a .conf extension; every .conf file there is loaded automatically. Reload Apache afterwards.

    How do I redirect HTTP to HTTPS in Apache?

    Create a VirtualHost on port 80 for your domain that contains only Redirect permanent / https://example.com/ and put the real site in the VirtualHost on port 443. Redirect keeps the rest of the path, so /about goes to https://example.com/about.

    How do I set up Apache as a reverse proxy?

    Enable mod_proxy and mod_proxy_http, then add ProxyPass / http://127.0.0.1:3000/ and ProxyPassReverse / http://127.0.0.1:3000/ inside the VirtualHost. ProxyPreserveHost On passes the original host name, and RequestHeader set X-Forwarded-Proto https tells the app that the visitor used HTTPS.

    How do I use PHP-FPM with Apache?

    Enable mod_proxy and mod_proxy_fcgi and send .php files to the PHP-FPM socket with a FilesMatch block containing SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost". This lets Apache use the event MPM and HTTP/2, which do not work with mod_php.

    Why does apachectl configtest fail with an SSL certificate error?

    SSLCertificateFile and SSLCertificateKeyFile must point to files that exist when Apache starts. Obtain the certificate first, for example with sudo certbot certonly --apache -d example.com, or temporarily disable HTTPS in the generator, deploy, get the certificate and then enable HTTPS.

    What is the difference between ServerName and ServerAlias?

    ServerName is the main host name of the virtual host and is used when Apache builds self-referencing URLs. ServerAlias lists additional names, such as www.example.com, that the same VirtualHost answers. Apache picks the virtual host whose ServerName or ServerAlias matches the Host header of the request.

    Is anything uploaded when I use this generator?

    No. The configuration is built in your browser, and your settings are only remembered in this browser's local storage.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Nginx Config GeneratorBuild an nginx server block: static site, SPA, reverse proxy or PHP, with SSL, gzip and redirects.Htaccess GeneratorBuild an Apache .htaccess file: HTTPS, www, gzip, caching, error pages, IP blocks, hotlinks.Htaccess & Nginx Redirect GeneratorBuild 301 redirects for .htaccess, Nginx and Netlify or Cloudflare _redirects.Systemd Service File GeneratorCreate a systemd .service unit with ExecStart, user, restart policy, environment and hardening.QR Code GeneratorMake QR codes for links, Wi-Fi, email and more.Barcode GeneratorCreate Code 128, EAN-13, UPC-A, EAN-8, Code 39 and ITF-14 barcodes as PNG or SVG.UUID GeneratorGenerate UUID v4 and v7 / GUIDs in bulk and copy or download them.Schema Markup Generator (JSON-LD)Create JSON-LD structured data for FAQ, Product, Article and more.Fake Data GeneratorGenerate mock data as JSON, CSV or SQL.Random String GeneratorGenerate secure random strings and tokens in bulk with any length and character set.API Key GeneratorCreate secure API keys and secrets with prefixes, checksums and SHA-256 hashes for storage.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.Cron Expression GeneratorBuild crontab schedules visually, read them in plain English and see the next run times.URL Slug GeneratorTurn titles into clean, SEO-friendly URL slugs: accents, stop words, separators and bulk lines.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.Gitignore GeneratorBuild a .gitignore from 50+ templates for languages, frameworks, IDEs and OS, merged and deduped.License GeneratorCreate a LICENSE file for MIT, Apache, GPL, BSD, ISC, MPL or Unlicense with your name and year.ULID GeneratorGenerate sortable ULIDs and UUID v7 in bulk, monotonic option, and decode their timestamps.Htpasswd GeneratorCreate .htpasswd entries with bcrypt, APR1-MD5 or SHA-1 for Apache and Nginx basic auth.Placeholder Image GeneratorCreate placeholder images in any size, color and text as PNG, JPG, WebP, SVG or data URI.Ads.txt GeneratorCreate or validate ads.txt and app-ads.txt files: seller lines, cert IDs and variables.Docker Run to Compose ConverterConvert docker run commands to docker-compose.yml, or a compose file back to docker run.Dockerfile GeneratorGenerate a production Dockerfile and .dockerignore for Node, Python, Go or a static nginx site.HTML Boilerplate GeneratorTick the options you need and get a clean HTML5 starter template with meta, OG tags and CSS reset.JSON to Zod SchemaInfer a Zod (or Yup) schema from sample JSON with optional, nullable and z.infer types.Linux Commands Cheat SheetSearchable Linux and bash command reference with flags explained, examples and copy buttons.LLMs.txt GeneratorBuild an llms.txt file for AI crawlers: summary and link sections, import from your sitemap.Nano ID GeneratorGenerate secure Nano IDs with custom alphabet, length and count, plus a collision calculator.OpenAPI / Swagger ViewerView OpenAPI 2/3 JSON or YAML as interactive API docs with validation and an endpoint list.package.json GeneratorFill a form and get a valid, npm-ready package.json with scripts, dependencies and checks.PKCE Code Challenge GeneratorGenerate an OAuth 2.0 PKCE code_verifier and S256 code_challenge, build auth URLs, verify pairs.README GeneratorFill in a form and get a polished README.md with badges, install, usage and license, live preview.Regex GeneratorBuild regular expressions visually from blocks or presets (email, date, phone) and test them live.Commit Message GeneratorBuild Conventional Commit messages with type, scope, body, breaking change and issue refs.Database Schema DesignerDesign tables and relationships visually, then export SQL for MySQL, PostgreSQL or SQLite.Docker Compose GeneratorBuild a docker-compose.yml with a form: services, ports, volumes, env, healthchecks and presets.Dummy File GeneratorCreate test files of an exact size in KB, MB or GB with zeros, random bytes or text.FFmpeg Command GeneratorPick a task and options, get the exact ffmpeg command with every flag explained.Article Schema GeneratorCreate Article, BlogPosting or NewsArticle JSON-LD with headline, authors, dates and images.Event Schema GeneratorCreate Event JSON-LD with dates, venue or online location, tickets, organizer and performers.Google Search Query BuilderBuild advanced Google searches with site:, filetype:, intitle:, exact phrases and date operators.HowTo Schema GeneratorCreate HowTo JSON-LD with steps, tools, supplies, total time and cost, then copy it.HTML Email Template BuilderDrag and drop blocks to build a responsive, table-based HTML email with inline styles.Organization Schema GeneratorCreate Organization JSON-LD with logo, URL, contact points, address and social profiles.PIN GeneratorGenerate random 4, 6 or 8-digit PINs that avoid sequences, repeats, dates and common PINs.Product Schema GeneratorBuild Product JSON-LD with price, availability, brand, GTIN, ratings and reviews.Question Keyword GeneratorFind the questions people ask about a topic, grouped by who, what, why, how, can and more.Recipe Schema GeneratorCreate Recipe JSON-LD with ingredients, steps, prep and cook times, nutrition and ratings.Security Headers GeneratorPick HSTS, CSP, frame, referrer and permissions options and get Apache, Nginx, Netlify or Cloudflare config.SKU GeneratorBuild consistent SKUs from brand, category, size and color, then export every variant as CSV.Typography Scale GeneratorBuild a modular type scale from a base size and ratio, then copy CSS variables or a Tailwind config.WordPress Salt GeneratorGenerate fresh WordPress security keys and salts for wp-config.php, .env or Docker in one click.ANSI Color Code GeneratorStyle terminal text with 16, 256 or RGB colors and get escape codes for bash, Python, JS and C.Bash Prompt GeneratorDrag and drop a custom PS1 prompt for bash or zsh with colors, git branch and a live preview.Changelog GeneratorTurn Conventional Commit messages into a grouped Keep a Changelog Markdown file per version.cURL Command BuilderBuild curl commands from a form: method, headers, query, JSON or form body, auth and flags.Docker Compose to KubernetesConvert docker-compose.yml into Kubernetes Deployment, Service, ConfigMap and PVC manifests.Docker Compose ValidatorCheck a docker-compose.yml for YAML errors, schema mistakes, broken references and deprecated keys.Dockerfile LinterLint a Dockerfile for best practices: pinned tags, apt cleanup, non-root USER and layer count.Dockerignore GeneratorBuild a .dockerignore from Node, Python, Go and Java templates, plus your own entries.ESLint Config GeneratorGenerate a flat eslint.config.js for JavaScript, TypeScript, React or Node with rule presets.Git Branch Name GeneratorTurn a ticket ID and title into a clean, valid git branch name like feature/PROJ-12-add-login.GitLab CI Config GeneratorGenerate a .gitlab-ci.yml with stages, jobs, images, cache, artifacts and rules from templates.Jinja2 Template TesterRender Jinja2 templates with YAML or JSON variables using real Jinja2, with clear error lines.JSON Schema Mock Data GeneratorGenerate realistic sample JSON from a JSON Schema: formats, patterns, $ref, seeds and counts.Kubernetes Secret GeneratorCreate Kubernetes Secret YAML from key/value pairs or .env with auto base64, or decode one.Kubernetes YAML ValidatorValidate Kubernetes manifests against the API schema of a chosen version, with error paths.Prettier Config GeneratorToggle Prettier options, preview formatted code live and copy your .prettierrc file.
    See all 85 Code Generators & Builders →