<?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>virtualHost &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/virtualhost/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>Fri, 20 Aug 2021 10:44:39 +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>Configuring Apache Access Control</title>
		<link>https://www.bestdevops.com/configuring-apache-access-control/</link>
		
		<dc:creator><![CDATA[pradeep]]></dc:creator>
		<pubDate>Fri, 20 Aug 2021 10:44:37 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[CORS]]></category>
		<category><![CDATA[headersModule]]></category>
		<category><![CDATA[virtualHost]]></category>
		<guid isPermaLink="false">https://www.bestdevops.com/?p=19512</guid>

					<description><![CDATA[Controlling Access Based on User Identity  Access to parts of a site can be restricted Require authentication and authorization [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">Controlling Access Based on User Identity</h2>



<p class="wp-block-paragraph"> <strong>Access to parts of a site can be restricted</strong><br>      Require authentication and authorization of the user</p>



<p class="wp-block-paragraph"><br><strong> User account information can be kept in several places</strong><br>       Plain text files<br>       DBM files<br>       MySQL database</p>



<p class="wp-block-paragraph"><strong>Here, we&#8217;ll restrict access to the &#8220;admin&#8221; section of our site to the</strong><br>         librarians Jim and Carla Since the number of users is small, we&#8217;ll store them in a plain text file</p>



<p class="wp-block-paragraph">Managing the User Account File</p>



<h2 class="wp-block-heading">1 Enable headers module</h2>



<p class="wp-block-paragraph">You need to enable headers module to enable CORS in Apache.</p>



<p class="wp-block-paragraph"><strong>Ubuntu/Debian</strong></p>



<p class="wp-block-paragraph">In ubuntu/debian linux, open terminal &amp; run the following command to enable headers module.</p>


<pre class="wp-block-code"><span><code class="hljs">$ sudo a2emod headers</code></span></pre>


<p class="wp-block-paragraph"><strong>CentOS/Redhat/Fedora</strong></p>



<p class="wp-block-paragraph">In CentOS/Redhat/Fedora linux, open the Apache configuration file <em>httpd.conf</em> and uncomment the following line by removing # in front of them.</p>



<pre class="wp-block-preformatted">LoadModule headers_module modules/mod_headers.so</pre>



<h2 class="wp-block-heading">2 Enable CORS in Apache</h2>



<p class="wp-block-paragraph">Next, add the “Header add Access-Control-Allow-Origin *” directive to either your Apache config file, or .htaccess file, or Virtual Host configuration file, depending on your requirement. If you add it to your main configuration file, CORS will be enabled to all websites on your server. If you add it to .htaccess file or  virtual host configuration file, then it will be enabled for only that file’s website. Here are examples of how to add this directive in different files. You can use any one of them.</p>



<p class="wp-block-paragraph"><strong>Directory Tag in Main Configuration File</strong></p>



<pre class="wp-block-preformatted">&lt;Directory /var/www/html&gt;
   ...
 &nbsp; Header set Access-Control-Allow-Origin "*"
   ...
&lt;/Directory&gt;</pre>



<p class="wp-block-paragraph">Anywhere in .htaccess file</p>



<pre class="wp-block-preformatted">   ...
   Header add Access-Control-Allow-Origin "*"
   ...</pre>



<p class="wp-block-paragraph">VirtualHost Tag in Virtual Host Configuration File</p>



<pre class="wp-block-preformatted">&lt;VirtualHost *:443&gt;
   ...
   Header add Access-Control-Allow-Origin "*"
   ...
&lt;/VirtualHost&gt;</pre>



<h2 class="wp-block-heading">Enable CORS from all websites</h2>



<p class="wp-block-paragraph">If you want to enable CORS for all websites, that is, accept cross domain requests from all websites, add the following</p>



<pre class="wp-block-preformatted">Header add Access-Control-Allow-Origin *;</pre>



<p class="wp-block-paragraph">In the above statement, we use wildcard (*) for Apache Access-Control-Allow-Origin directive</p>



<h3 class="wp-block-heading">Enable&nbsp; CORS from one domain</h3>



<p class="wp-block-paragraph">If you want to enable CORS for one website domain (e.g example.com), specify that domain in place of wildcard character *.</p>



<pre class="wp-block-preformatted">Header add Access-Control-Allow-Origin "example.com";</pre>



<h3 class="wp-block-heading">Enable CORS from multiple domains</h3>



<p class="wp-block-paragraph">If you want to enable CORS for multiple domains (e.g example1.com, example2.com,example3.com), specify them separately one after another</p>



<pre class="wp-block-preformatted">Header add Access-Control-Allow-Origin "example1.com";
Header add Access-Control-Allow-Origin "example2.com";
Header add Access-Control-Allow-Origin "example3.com";</pre>



<h3 class="wp-block-heading">Enable CORS from localhost</h3>



<p class="wp-block-paragraph">If you want to enable CORS from localhost, add 127.0.0.1 or localhost in place of domain name</p>



<pre class="wp-block-preformatted">Header add Access-Control-Allow-Origin "localhost";</pre>



<h2 class="wp-block-heading">3. Restart Apache Server</h2>



<p class="wp-block-paragraph">Restart Apache web server to apply changes</p>



<pre class="wp-block-preformatted">-------------- On Debian/Ubuntu -------------- 
# apache2 -t
# systemctl restart apache2.service

-------------- On RHEL/CentOS/Fedora --------------
# httpd -t
# systemctl restart httpd.service</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
