<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>virtualhosts &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/virtualhosts/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bestdevops.com</link>
	<description>Lets Learn, Do it &#38; Share! Thats a Best DevOps!!!</description>
	<lastBuildDate>Thu, 15 May 2025 05:32:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>Apache HTTP Server: The Backbone of the Web</title>
		<link>https://www.bestdevops.com/apache-http-server-the-backbone-of-the-web/</link>
					<comments>https://www.bestdevops.com/apache-http-server-the-backbone-of-the-web/#respond</comments>
		
		<dc:creator><![CDATA[vijay1 vijay1]]></dc:creator>
		<pubDate>Thu, 15 May 2025 05:32:46 +0000</pubDate>
				<category><![CDATA[DevOps]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[OpenSource]]></category>
		<category><![CDATA[ServerArchitecture]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[virtualhosts]]></category>
		<category><![CDATA[Webserver]]></category>
		<guid isPermaLink="false">https://www.bestdevops.com/?p=31137</guid>

					<description><![CDATA[What is Apache? Apache HTTP Server, commonly referred to as Apache, is one of the most popular and widely used [&#8230;]]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="576" src="https://www.bestdevops.com/wp-content/uploads/2025/05/image-45-1024x576.png" alt="" class="wp-image-31143" srcset="https://www.bestdevops.com/wp-content/uploads/2025/05/image-45-1024x576.png 1024w, https://www.bestdevops.com/wp-content/uploads/2025/05/image-45-300x169.png 300w, https://www.bestdevops.com/wp-content/uploads/2025/05/image-45-768x432.png 768w, https://www.bestdevops.com/wp-content/uploads/2025/05/image-45.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">What is Apache?</h2>



<p class="wp-block-paragraph">Apache HTTP Server, commonly referred to as Apache, is one of the most popular and widely used open-source web servers in the world. Originally developed by the Apache Software Foundation and first released in 1995, Apache plays a critical role in serving web content over the Internet.</p>



<p class="wp-block-paragraph">Apache acts as a software intermediary between a client (such as a web browser) and the web server’s content (HTML files, images, scripts, etc.). It receives requests from clients and serves back the appropriate responses. Apache supports a wide range of features, including dynamic content processing, authentication, SSL/TLS encryption, URL rewriting, and load balancing.</p>



<p class="wp-block-paragraph">Apache’s modular architecture, reliability, and robust community support have made it the de facto choice for web hosting, powering a significant portion of the internet’s websites.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Major Use Cases of Apache</h2>



<h3 class="wp-block-heading">1. <strong>Web Hosting</strong></h3>



<p class="wp-block-paragraph">Apache is widely used to host websites, from simple static pages to complex, dynamic applications. It supports various content types and scripting languages (PHP, Python, Perl).</p>



<h3 class="wp-block-heading">2. <strong>Serving Dynamic Web Content</strong></h3>



<p class="wp-block-paragraph">By integrating with server-side technologies like CGI, FastCGI, and modules such as mod_php, Apache can serve dynamic web content generated by applications.</p>



<h3 class="wp-block-heading">3. <strong>Reverse Proxy and Load Balancing</strong></h3>



<p class="wp-block-paragraph">Apache can act as a reverse proxy server, forwarding client requests to backend servers, balancing load, and providing fault tolerance.</p>



<h3 class="wp-block-heading">4. <strong>Secure Web Server</strong></h3>



<p class="wp-block-paragraph">Apache supports HTTPS through SSL/TLS modules, providing encrypted communication for secure web applications.</p>



<h3 class="wp-block-heading">5. <strong>Virtual Hosting</strong></h3>



<p class="wp-block-paragraph">Apache supports hosting multiple websites/domains on a single server, each with its own configuration.</p>



<h3 class="wp-block-heading">6. <strong>API Gateway</strong></h3>



<p class="wp-block-paragraph">By handling HTTP requests, Apache can be used as a gateway to backend APIs, adding features such as caching, authentication, and rate limiting.</p>



<h3 class="wp-block-heading">7. <strong>Content Compression and Caching</strong></h3>



<p class="wp-block-paragraph">Modules allow Apache to compress responses (e.g., gzip) and cache frequently requested content, enhancing performance.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">How Apache Works Along with Architecture</h2>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="338" src="https://www.bestdevops.com/wp-content/uploads/2025/05/image-46-1024x338.png" alt="" class="wp-image-31144" srcset="https://www.bestdevops.com/wp-content/uploads/2025/05/image-46-1024x338.png 1024w, https://www.bestdevops.com/wp-content/uploads/2025/05/image-46-300x99.png 300w, https://www.bestdevops.com/wp-content/uploads/2025/05/image-46-768x254.png 768w, https://www.bestdevops.com/wp-content/uploads/2025/05/image-46-1536x507.png 1536w, https://www.bestdevops.com/wp-content/uploads/2025/05/image-46.png 1856w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p class="wp-block-paragraph">Apache follows a client-server model where the server listens for HTTP requests and responds accordingly.</p>



<h3 class="wp-block-heading">Core Architectural Components:</h3>



<ul class="wp-block-list">
<li><strong>Main Process</strong></li>
</ul>



<p class="wp-block-paragraph">The main Apache process runs with administrative privileges, managing configuration, spawning worker processes/threads, and handling shutdowns and restarts.</p>



<ul class="wp-block-list">
<li><strong>Child Processes/Workers</strong></li>
</ul>



<p class="wp-block-paragraph">These are spawned by the main process to handle incoming HTTP requests. Depending on the Multi-Processing Module (MPM) used, Apache can handle requests using multiple processes, threads, or a combination.</p>



<ul class="wp-block-list">
<li><strong>Modules</strong></li>
</ul>



<p class="wp-block-paragraph">Apache’s modular architecture allows extending core functionality with loadable modules (DSOs). Modules provide features like URL rewriting, authentication, SSL support, logging, caching, and more. Common modules include:</p>



<ul class="wp-block-list">
<li><code>mod_ssl</code>: SSL/TLS support</li>



<li><code>mod_rewrite</code>: URL rewriting</li>



<li><code>mod_proxy</code>: Proxying requests</li>



<li><code>mod_auth</code>: Authentication mechanisms</li>



<li><code>mod_cache</code>: Caching</li>



<li><strong>Configuration Files</strong></li>
</ul>



<p class="wp-block-paragraph">Apache’s behavior is controlled through configuration files, primarily <code>httpd.conf</code> and additional files like <code>.htaccess</code> for directory-level configuration overrides.</p>



<ul class="wp-block-list">
<li><strong>Request Handling Flow</strong>
<ol class="wp-block-list">
<li>Client sends an HTTP request.</li>



<li>Apache accepts the connection via socket.</li>



<li>The request is parsed and routed based on the URL and configuration.</li>



<li>Appropriate modules are invoked to process the request.</li>



<li>Content is served (static or dynamically generated).</li>



<li>Response is sent back to the client.</li>
</ol>
</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading">Multi-Processing Modules (MPMs)</h3>



<p class="wp-block-paragraph">MPMs define how Apache manages connections:</p>



<ul class="wp-block-list">
<li><strong>prefork MPM:</strong> Uses multiple child processes with one thread each; preferred for compatibility with non-thread-safe libraries.</li>



<li><strong>worker MPM:</strong> Uses fewer child processes with multiple threads; more efficient for high loads.</li>



<li><strong>event MPM:</strong> Similar to worker but optimized for handling keep-alive connections efficiently.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Basic Workflow of Apache</h2>



<ol class="wp-block-list">
<li><strong>Server Initialization</strong></li>
</ol>



<p class="wp-block-paragraph">Upon startup, Apache reads its configuration files, loads necessary modules, and initializes worker processes or threads.</p>



<ol start="2" class="wp-block-list">
<li><strong>Listening for Connections</strong></li>
</ol>



<p class="wp-block-paragraph">Apache listens on configured IP addresses and ports (typically port 80 for HTTP, 443 for HTTPS).</p>



<ol start="3" class="wp-block-list">
<li><strong>Accepting Client Requests</strong></li>
</ol>



<p class="wp-block-paragraph">When a client (browser or API consumer) sends a request, Apache accepts it and creates a request object.</p>



<ol start="4" class="wp-block-list">
<li><strong>Request Processing</strong></li>
</ol>



<p class="wp-block-paragraph">Apache determines how to process the request using its configuration, routing it to the appropriate handler module.</p>



<ol start="5" class="wp-block-list">
<li><strong>Content Generation</strong></li>
</ol>



<p class="wp-block-paragraph">The requested content (static files or dynamic scripts) is retrieved or generated.</p>



<ol start="6" class="wp-block-list">
<li><strong>Response Delivery</strong></li>
</ol>



<p class="wp-block-paragraph">Apache sends the HTTP response back to the client, including headers and body content.</p>



<ol start="7" class="wp-block-list">
<li><strong>Connection Handling</strong></li>
</ol>



<p class="wp-block-paragraph">Depending on configuration, Apache may keep the connection alive for further requests or close it.</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Step-by-Step Getting Started Guide for Apache</h2>



<h3 class="wp-block-heading">Step 1: Install Apache</h3>



<ul class="wp-block-list">
<li>On <strong>Linux (Ubuntu/Debian):</strong></li>
</ul>


<pre class="wp-block-code"><span><code class="hljs">sudo apt update
sudo apt install apache2
</code></span></pre>


<ul class="wp-block-list">
<li>On <strong>CentOS/RHEL:</strong></li>
</ul>


<pre class="wp-block-code"><span><code class="hljs">sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd
</code></span></pre>


<ul class="wp-block-list">
<li>On <strong>Windows:</strong></li>
</ul>



<p class="wp-block-paragraph">Download from <a href="https://www.apachelounge.com/download/">Apache Lounge</a> and follow the installer instructions.</p>



<h3 class="wp-block-heading">Step 2: Verify Installation</h3>



<p class="wp-block-paragraph">Open a browser and navigate to <code>http://localhost</code>. You should see the Apache default welcome page.</p>



<p class="wp-block-paragraph">Alternatively, run:</p>


<pre class="wp-block-code"><span><code class="hljs">apachectl status
</code></span></pre>


<p class="wp-block-paragraph">or</p>


<pre class="wp-block-code"><span><code class="hljs">systemctl status apache2
</code></span></pre>


<h3 class="wp-block-heading">Step 3: Configure Apache</h3>



<ul class="wp-block-list">
<li>Configuration files are located at:
<ul class="wp-block-list">
<li><code>/etc/apache2/</code> (Ubuntu/Debian)</li>



<li><code>/etc/httpd/</code> (CentOS/RHEL)</li>



<li>Apache’s <code>httpd.conf</code> file is the primary configuration file.</li>
</ul>
</li>



<li>Edit configuration files with a text editor, e.g.,</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo nano /etc/apache2/sites-available/<span class="hljs-number">000</span>-<span class="hljs-keyword">default</span>.conf
</code></span></pre>


<h3 class="wp-block-heading">Step 4: Serve Your Website</h3>



<ul class="wp-block-list">
<li>Place your website files (HTML, CSS, JS) in the web root directory:
<ul class="wp-block-list">
<li><code>/var/www/html</code> on most Linux systems.</li>
</ul>
</li>



<li>Test by navigating to <code>http://localhost/index.html</code>.</li>
</ul>



<h3 class="wp-block-heading">Step 5: Enable Modules</h3>



<ul class="wp-block-list">
<li>Enable modules like SSL or rewrite as needed:</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs">sudo a2enmod ssl
sudo a2enmod rewrite
sudo systemctl restart apache2
</code></span></pre>


<h3 class="wp-block-heading">Step 6: Set Up Virtual Hosts</h3>



<p class="wp-block-paragraph">To serve multiple sites:</p>



<ul class="wp-block-list">
<li>Create separate configuration files under <code>sites-available</code>, e.g.,</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs">sudo nano /etc/apache2/sites-available/example.com.conf
</code></span></pre>


<ul class="wp-block-list">
<li>Enable the site:</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs language-css"><span class="hljs-selector-tag">sudo</span> <span class="hljs-selector-tag">a2ensite</span> <span class="hljs-selector-tag">example</span><span class="hljs-selector-class">.com</span><span class="hljs-selector-class">.conf</span>
<span class="hljs-selector-tag">sudo</span> <span class="hljs-selector-tag">systemctl</span> <span class="hljs-selector-tag">reload</span> <span class="hljs-selector-tag">apache2</span>
</code></span></pre>


<h3 class="wp-block-heading">Step 7: Configure Firewall</h3>



<p class="wp-block-paragraph">Allow HTTP and HTTPS traffic:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">sudo ufw allow <span class="hljs-string">'Apache Full'</span>
</code></span></pre>


<h3 class="wp-block-heading">Step 8: Enable HTTPS (Optional)</h3>



<ul class="wp-block-list">
<li>Use Let’s Encrypt for free SSL certificates:</li>
</ul>


<pre class="wp-block-code"><span><code class="hljs">sudo apt install certbot python3-certbot-apache
sudo certbot --apache
</code></span></pre>


<h3 class="wp-block-heading">Step 9: Monitor Logs and Performance</h3>



<ul class="wp-block-list">
<li>Access logs: <code>/var/log/apache2/access.log</code></li>



<li>Error logs: <code>/var/log/apache2/error.log</code></li>
</ul>



<p class="wp-block-paragraph">Use logs to troubleshoot and optimize performanc</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.bestdevops.com/apache-http-server-the-backbone-of-the-web/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Setup Virtual Hosts with Apache Web Server on Linux</title>
		<link>https://www.bestdevops.com/setup-virtual-hosts-with-apache-web-server-on-linux/</link>
		
		<dc:creator><![CDATA[pradeep]]></dc:creator>
		<pubDate>Mon, 09 Aug 2021 09:34:09 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Vmware]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[virtualhosts]]></category>
		<guid isPermaLink="false">https://www.bestdevops.com/?p=18889</guid>

					<description><![CDATA[First thing you need to do is to install apache in your machine. Apache Installation Apache gives its functionality and [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">First thing you need to do is to install apache in your machine.</h2>



<h3 class="wp-block-heading">Apache Installation</h3>



<p class="wp-block-paragraph">Apache gives its functionality and the components to individual units which can be customized and configured independently. The basic unit that describes a site or a domain is called a virtual host.</p>



<p class="wp-block-paragraph">This allows the administrator to use one server to host multiple domains or sites with a single interface or IP address by using a mechanism.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo apt-<span class="hljs-keyword">get</span> update
$ sudo apt-<span class="hljs-keyword">get</span> install apache2</code></span></pre>


<h3 class="wp-block-heading">Create the Directory Structure</h3>



<p class="wp-block-paragraph">A directory structure shall hold the site information and data which will be served to visitors. By default, the top-level directory for apache is /var/www and we will be setting them to the individual directories under the /var/www directory for each site/domain.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo mkdir -p /<span class="hljs-keyword">var</span>/www/firstSite.com
$ sudo mkdir -p /<span class="hljs-keyword">var</span>/www/secondSite.com</code></span></pre>


<h3 class="wp-block-heading">Grant Permissions</h3>



<p class="wp-block-paragraph">Our directory&#8217;s owned by our root user. If we want our normal user to be able to modify files in our web directories, then we have to change the ownership to others normal users.</p>


<pre class="wp-block-code"><span><code class="hljs language-php">$ sudo chown -R $USER:$USER /<span class="hljs-keyword">var</span>/www/firstSite.com
$ sudo chown -R $USER:$USER /<span class="hljs-keyword">var</span>/www/secondSite.com
$ sudo chmod -R <span class="hljs-number">755</span> /<span class="hljs-keyword">var</span>/www</code></span></pre>


<h3 class="wp-block-heading">Create Demo Pages for for both sites.</h3>



<p class="wp-block-paragraph">To create a file we use touch command, The <em>touch command</em> is a standard command used in UNIX/<em>Linux</em> operating system which is used to create, change and modify timestamps of a file.</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ touch /<span class="hljs-keyword">var</span>/www/webserver1.com/index.html</code></span></pre>


<p class="wp-block-paragraph">Then put some lines of html.</p>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Site one<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Site one heading<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>My first paragraph.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span>
</code></span></pre>


<p class="wp-block-paragraph">We&#8217;ll copy and past the same page for second server and modify it accordingly</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ cp /<span class="hljs-keyword">var</span>/www/firstSite.com/index.html /<span class="hljs-keyword">var</span>/www/secondSite.com/index.html</code></span></pre>

<pre class="wp-block-code"><span><code class="hljs language-xml">$ nano /var/www/webserver2.com/index.html
<span class="hljs-tag">&lt;<span class="hljs-name">html</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Welcome to secondSite.com!<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
   <span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
   <span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Success!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
   <span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span></code></span></pre>


<h3 class="wp-block-heading">Create New Virtual Host Files</h3>


<pre class="wp-block-code"><span><code class="hljs language-javascript">$ sudo cp /etc/apache2/sites-available/<span class="hljs-number">000</span>-<span class="hljs-keyword">default</span>.conf /etc/apache2/sites-available/firstSite.conf
$ sudo nano /etc/apache2/sites-available/firstSite.com.conf</code></span></pre>

<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">VirtualHost</span> *<span class="hljs-attr">:80</span>&gt;</span>
   ServerAdmin admin@firstSite.com
   ServerName firstSite.com
   ServerAlias www.firstSite.com
   DocumentRoot /var/www/firstSite.com/
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
<span class="hljs-tag">&lt;/<span class="hljs-name">VirtualHost</span>&gt;</span></code></span></pre>


<p class="wp-block-paragraph">Copy First Virtual Host file and customize for Second Domain webserver2.com</p>



<pre class="wp-block-preformatted">$ sudo cp /etc/apache2/sites-available/firstSite.com.conf /etc/apache2/sites-available/secondSite.com.conf
$ sudo nano /etc/apache2/sites-available/secondSite.com.conf</pre>



<p class="wp-block-paragraph">Do the same thing for secondSite VH</p>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="hljs-tag">&lt;<span class="hljs-name">VirtualHost</span> *<span class="hljs-attr">:80</span>&gt;</span>
   ServerAdmin admin@secondSite.com
   ServerName secondSite.com
   ServerAlias www.secondSite.com
   DocumentRoot /var/www/secondSite.com/
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined
<span class="hljs-tag">&lt;/<span class="hljs-name">VirtualHost</span>&gt;</span></code></span></pre>


<h3 class="wp-block-heading">Enable the New Virtual Host Files</h3>


<pre class="wp-block-code"><span><code class="hljs">$ sudo a2ensite webserver1.com.conf
$ sudo a2ensite webserver2.com.conf</code></span></pre>


<p class="wp-block-paragraph">We needed to restart Apache server</p>


<pre class="wp-block-code"><span><code class="hljs">$ sudo service apache2 restart</code></span></pre>


<h3 class="wp-block-heading">Testing the Websites</h3>


<pre class="wp-block-code"><span><code class="hljs">$ sudo /etc/hosts</code></span></pre>


<pre class="wp-block-preformatted">192.168.1.84 website1.com
192.168.1.84 website1.com</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
