<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>The Ops Community ⚙️: Tikam Alma</title>
    <description>The latest articles on The Ops Community ⚙️ by Tikam Alma (@tikam_alma).</description>
    <link>https://community.ops.io/tikam_alma</link>
    <image>
      <url>https://community.ops.io/images/bA1pHWyaFEMu__Rb13VMYwR5fFgId9k9kJMUe1OqK6A/rs:fill:90:90/g:sm/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL3Vz/ZXIvcHJvZmlsZV9p/bWFnZS8xMjAvODdk/NTE2ZTYtMmVhYy00/MzBmLThiODYtOWNi/MmY1MTU3NGE2LnBu/Zw</url>
      <title>The Ops Community ⚙️: Tikam Alma</title>
      <link>https://community.ops.io/tikam_alma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://community.ops.io/feed/tikam_alma"/>
    <language>en</language>
    <item>
      <title>Deploy Backend Server Using Apache Webserver</title>
      <dc:creator>Tikam Alma</dc:creator>
      <pubDate>Thu, 26 May 2022 04:52:13 +0000</pubDate>
      <link>https://community.ops.io/tikam_alma/deploy-backend-server-using-apache-webserver-28a3</link>
      <guid>https://community.ops.io/tikam_alma/deploy-backend-server-using-apache-webserver-28a3</guid>
      <description>&lt;h2&gt;
  
  
  How do the backend servers work?
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;What is a backend server?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The backend servers are the main component of any functional website which uses API, databases, and other features. &lt;br&gt;
What the user sees on the browser is the frontend website and the processing of the login, signup, storing credentials, and data are done by backend servers on cloud services. &lt;br&gt;
Frontend servers are rendered on the client-side, and backend servers are rendered on the server-side, and on the server, it processes all the complex functions and receives data from the database so that the frontend server can use it. &lt;/p&gt;

&lt;p&gt;Hosting backend servers in any cloud system requires different configurations for each of the, there are different programming languages and the most popular programming languages which are used for writing backend servers are Python, Go, Javascript, PHP, RUBY Java. &lt;br&gt;
Each language has its own framework to write backend servers, for python language Django framework is used widely, for javascript Node is used, for Go, Gin framework is used.&lt;/p&gt;
&lt;h2&gt;
  
  
  Dependency and required configurations for hosting backend servers
&lt;/h2&gt;

&lt;p&gt;Different backend servers are built on different languages and different languages have their own frameworks and each framework has its own required dependency and tools to work on web servers.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Python - WSGI (Web Server Gateway Interface)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Building projects in Django creates auto-generated files by default which are the skeleton or the structure of the Django framework, wsgi.py is one such important file that is used to communicate with web servers. WSGI is Web Server Gateway Interface, it describes the communication between web servers and Python web application servers or frameworks.&lt;br&gt;
WSGI (Web Server Gateway Interface) is a standard interface between web server software and web applications written in Python.&lt;br&gt;
It covers how a web server connects with Python web applications/frameworks, as well as how web applications/frameworks may be chained together to execute a request.&lt;/p&gt;

&lt;p&gt;The apache webservers are popular for their customization and multi-platform support, it has a specific module for Django servers, called mod_wsgi. The mod WSGI module provides a WSGI compliant interface for executing and running a python based web application server within apache.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Node - Proxy Module&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In an apache web server, the node or javascript servers are hosted or run using the proxypass and reverse proxy method and its modules.&lt;/p&gt;

&lt;p&gt;A reverse proxy serves as a link between the client and the server, forwarding requests to the main web server or application webservers. It manages the requests and responses between clients and servers and offers security and a high level of abstraction.&lt;/p&gt;

&lt;p&gt;The ProxyPass directive defines how inbound requests are routed to the backend server (or a cluster of servers known as a Balancer group). &lt;/p&gt;

&lt;p&gt;And another directive used is the ProxyPass directive, which defines how the inbound requests are sent to the Node/Javascript backend servers, it manages any requests or responses under the root URL (/) that should be sent or routes to the Node/Javascript backed servers localhost address or the root default address.&lt;/p&gt;

&lt;p&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Hosting backend servers in the cloud
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Django server configurations
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Setup and install the Django dependencies and packages.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The basic requirements for hosting the Django server are its requiremnets.txt file in which all of the dependency packages are written and connecting it to the database and running its migrations.&lt;/p&gt;

&lt;p&gt;For installing the dependency and packages, check the python version which the Django project application needs to be set and make a virtual environment upon which the Django server will run.&lt;/p&gt;

&lt;p&gt;In any cloud service, Linux servers are mostly used, use these commands to check the python version and virtual environment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install all Python 3 packages. These will ensure we have everything for Python - Django framework application server.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Update the Linux/ubuntu system&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt-get update &amp;amp;&amp;amp; sudo apt-get dist-upgrade
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo apt install -y python3-pip python3 python3-setuptools build-essential libssl-dev libffi-dev python3-dev python3-venv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Make a virtual environment
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ mkdir project_env
## Directory where environment files can be stored

$ cd project_env
$ python3 -m venv penv
## penv can be named anything
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Activate virtulenv  and it should look like this :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd project_env
$ source penv/bin/activate
(penv)[user]$ / directory /
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install the packages inside the virtualenv
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pip install package_name
OR
$ pip install -r requiremenrs.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Configuring WSGI.py&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Django autogenerates the wsgi.py file inside the main directory of django alonside settings.py and other files.&lt;/p&gt;

&lt;p&gt;Open the wsgi.py and configure the project directory path.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
"""
WSGI config for lgraph project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""

import os
import sys
from django.core.wsgi import get_wsgi_application

## Add this line to add project directory.
sys.path.append('/home/your_project')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")

application = get_wsgi_application()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Installing and enabling "Mod WSGI"&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apt-get update
sudo apt-get install libapache2-mod-wsgi-py3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enabling the mod_wsgi module server wide.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ a2enmod wsgi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Django doundation has offical docmentation about how to used mod_wsgi with django - &lt;a href="https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/modwsgi/"&gt;https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/modwsgi/&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Running and testing Django server in localhost&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After setting up the django application, now start the server, check if everything is working, start the django server with these commands:&lt;/p&gt;

&lt;p&gt;To migrate the database, get static files ready and to test run the Django application server use these commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ python manage.py makemigrations
$ python manage.py migrate
$ python manage.py collectstatic
$ python manage.py runserver 0.0.0.0:8000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Node server configuration
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Setup  Setup and install the Node dependencies and packages&lt;/p&gt;

&lt;p&gt;Running and testing node server in localhost&lt;/p&gt;

&lt;p&gt;Install and enable proxy_modules&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Configuring apache virtualhost to serve the backend servers.
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Configuring Virtualhost for Django Backend Server&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After enabling the mod_wsgi, now it's time to configure the virtualhost to deploy the application server to expose it to internet&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;enable mod wsgi
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ a2enmod wsgi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the &lt;code&gt;/etc/apache2/site-available&lt;/code&gt; directory and edit the project's configuration file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ cd /etc/apache2/sites-available
$ /etc/apache2/sites-available / ~ ls
$ ls

$ nano django-project.conf
OR 
$ vim django-project.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure  and add the following line:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;WSGIScriptAlias&lt;/li&gt;
&lt;li&gt;WSGIDaemonProcess&lt;/li&gt;
&lt;li&gt;WSGIProcessGroup
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt; 
 ServerName mysite.example.com 
 DocumentRoot /var/www/vhosts/mysite 
 WSGIScriptAlias / /var/www/vhosts/mysite/myproject/wsgi.py 

 # adjust the following line to match your Python path 
 WSGIDaemonProcess mysite.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/vhosts/mysite/venv/lib/python3.5 
 WSGIProcessGroup mysite.example.com 

 &amp;lt;directory /var/www/vhosts/mysite&amp;gt; 
   AllowOverride all 
   Require all granted 
   Options FollowSymlinks 
 &amp;lt;/directory&amp;gt; 

 Alias /static/ /var/www/vhosts/mysite/static/ 

 &amp;lt;Directory /var/www/vhosts/mysite/static&amp;gt; 
  Require all granted 
 &amp;lt;/Directory&amp;gt; 
&amp;lt;/VirtualHost&amp;gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Configuring Virtualhost for Node Backend Server&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Dry run and testing the live servers
&lt;/h2&gt;

&lt;p&gt;To check the application server is running or not &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Check the apache webserver status&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check the application server status&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Curl localhost:80 &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If in the cloud get the public IP and open the web application using the IP or domain set in the configuration file.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>devops</category>
      <category>tutorials</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to make Apache2 server faster - Part-02 [Implementation]</title>
      <dc:creator>Tikam Alma</dc:creator>
      <pubDate>Wed, 25 May 2022 21:20:34 +0000</pubDate>
      <link>https://community.ops.io/tikam_alma/how-to-make-apache2-server-faster-part-02-implementation-1e0i</link>
      <guid>https://community.ops.io/tikam_alma/how-to-make-apache2-server-faster-part-02-implementation-1e0i</guid>
      <description>&lt;p&gt;I will explain here how to increase latency of apache2 server,using Django deployment example.At the end of the article you'll get to know that this can be applies to any backend server be it Django or node server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing mod_wsgi the easy way
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;pip install mod_wsgi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;mod_wsgi - module for apache web server&lt;/p&gt;

&lt;h3&gt;
  
  
  No Apache Configuration Required
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="s"&gt;$ mod_wsgi-express start-server hello.wsgi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Django Framework Integration
&lt;/h3&gt;

&lt;p&gt;INSTALLED_APPS = [&lt;/p&gt;

&lt;p&gt;'django.contrib.admin',&lt;/p&gt;

&lt;p&gt;'django.contrib.auth',&lt;/p&gt;

&lt;p&gt;.....&lt;/p&gt;

&lt;p&gt;.....&lt;/p&gt;

&lt;p&gt;'mod_wsgi.server',&lt;/p&gt;

&lt;p&gt;]&lt;/p&gt;

&lt;h3&gt;
  
  
  Send logging to terminal
&lt;/h3&gt;

&lt;p&gt;settings.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;LOGGING&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;#  ... omitting the formatters and handlers for brevity ...
&lt;/span&gt;    &lt;span class="s"&gt;'loggers'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;# ...  you may have other loggers here as well ...
&lt;/span&gt;        &lt;span class="s"&gt;'django'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="s"&gt;'handlers'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'name_of_your_file_handler_goes_here'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
            &lt;span class="s"&gt;'level'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'DEBUG'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="s"&gt;'propagate'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;LOGGING&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="s"&gt;'version'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'disable_existing_loggers'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s"&gt;'handlers'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="s"&gt;'console'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                        &lt;span class="s"&gt;'class'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;'logging.StreamHandler'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                 &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="s"&gt;'loggers'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="s"&gt;'django'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                            &lt;span class="s"&gt;'handlers'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;'console'&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
                            &lt;span class="s"&gt;'level'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'DJANGO_LOG_LEVEL'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;'INFO'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                    &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run Django With Management command
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;runmodwsgi&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Automatic code reloading
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;runmodwsgi&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt;&lt;span class="nb"&gt;reload&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;on&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;changes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Django DEBUG settings
&lt;/h3&gt;

&lt;p&gt;settings.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'MOD_WSGI_DEBUG_MODE'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;DEBUG&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'MOD_WSGI_DEBUGGER_ENABLED'&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;DEBUG_PROPAGATE_EXCEPTIONS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Interactive Debugger
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;runmodwsgi&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt;&lt;span class="n"&gt;enable&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;debugger&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Production configuration
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;python&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="n"&gt;manage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;runmodwsgi&lt;/span&gt; \
&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;wsgi&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;  \
&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt; &lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;\
&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="mi"&gt;80&lt;/span&gt;  &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;setup&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;only&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;wsgi&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;apachectl&lt;/span&gt; &lt;span class="n"&gt;start&lt;/span&gt; 
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;wsgi&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;apachectl&lt;/span&gt; &lt;span class="n"&gt;restart&lt;/span&gt; 
&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;etc&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;wsgi&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;80&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;apachectl&lt;/span&gt; &lt;span class="n"&gt;stop&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Use daemon mode of mod_wsgi
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;WSGIRestrictedEmbedded&lt;/span&gt; &lt;span class="n"&gt;On&lt;/span&gt;
&lt;span class="n"&gt;WSGIDaemonProcess&lt;/span&gt; &lt;span class="n"&gt;myapp&lt;/span&gt; &lt;span class="n"&gt;python&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;=/&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;

&lt;span class="n"&gt;WSGIScriptAlias&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;wsgi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt; \ 
        &lt;span class="n"&gt;process&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;myapp&lt;/span&gt; &lt;span class="n"&gt;application&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;group&lt;/span&gt;&lt;span class="o"&gt;=%&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;GLOBAL&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Directory&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Files&lt;/span&gt; &lt;span class="n"&gt;wsgi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;py&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="n"&gt;Require&lt;/span&gt; &lt;span class="nb"&gt;all&lt;/span&gt; &lt;span class="n"&gt;granted&lt;/span&gt;
        &lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;Files&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;Directory&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just add whatever the backend server Django or Node anything, putting this above virtualhost on line-1 will boost your latency.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WSGIRestrictedEmbedded On
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Resources:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://youtu.be/H6Q3l11fjU0"&gt;https://youtu.be/H6Q3l11fjU0&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://modwsgi.readthedocs.io/en/master/"&gt;mod_wsgi - mod_wsgi 4.8.0 documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>tutorials</category>
      <category>productivity</category>
    </item>
    <item>
      <title>How to make Apache2 server faster - Part-01 [Theory]</title>
      <dc:creator>Tikam Alma</dc:creator>
      <pubDate>Wed, 25 May 2022 21:19:06 +0000</pubDate>
      <link>https://community.ops.io/tikam_alma/how-to-make-apache2-server-faster-part-01-theory-1oe0</link>
      <guid>https://community.ops.io/tikam_alma/how-to-make-apache2-server-faster-part-01-theory-1oe0</guid>
      <description>&lt;h3&gt;
  
  
  Making Apache Suck Less -1
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Don't use apache default configurations for hosting python web applications.&lt;/li&gt;
&lt;li&gt;Don't use the prefork MPM unless you know how to configure Apache Properly,use the worker MPM, it is more forgiving.&lt;/li&gt;
&lt;li&gt;Don't allow apache to automatically scale out the number of processes over too great a range.&lt;/li&gt;
&lt;li&gt;Don't try and use a single Apache instance to host Python,PHP,Perl Web application at the same time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Making Apache Suck Less -1
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure MaxSpareServers is greater than MinSpareServers.If you don't,Apache will set MaxSpareServers to be MinSpareServers+1 for you anyway.&lt;/li&gt;
&lt;li&gt;Don't set StartServers to be less than MinSpareServers as it will delay start up of processes so as to reach minimum spare required.&lt;/li&gt;
&lt;li&gt;Don't set StartServers to be greater than MaxSpareServers as processes will start to be killed off immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Overhead of Process Creation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Initialization of Python interpreter&lt;/li&gt;
&lt;li&gt;Loading of the WSGI application&lt;/li&gt;
&lt;li&gt;Loading of required standard library modules&lt;/li&gt;
&lt;li&gt;Loading of required third party modules&lt;/li&gt;
&lt;li&gt;Initialization of the WSGI application&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What MPM are you using?
&lt;/h3&gt;

&lt;p&gt;$ apachectl -V | grep 'Server MPM'&lt;/p&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;p&gt;$ /user/sbin/httpd -V | grep 'Server MPM'&lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-loading is a security Risk
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;You don't necessarily know which WSGI application to load until the first request arrives for it.&lt;/li&gt;
&lt;li&gt;Python web application aren't usually designed properly for preloading prior to forking of worker processes.&lt;/li&gt;
&lt;li&gt;All code run in the Apache parent process is run as root.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When using mod_wsgi  five initialization  is deferred until after the processes forked, any application code required python modules are then lazily loaded, if initializing python and loading wsgi application in the worker process can be expensive, &lt;/p&gt;

&lt;p&gt;Why can't we preload everything in Apache parent process before the worker process were forked.&lt;/p&gt;

&lt;p&gt;Even if a python web application were designed to be able to pre-loaded and run properly after the processes was forked the key issue that uses application ocuured on startup would run as root, if executed in the parent process and this is one very big security risk.&lt;/p&gt;

&lt;h3&gt;
  
  
  Preloading causes memory leaks
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;The python interpreter will leak memory into the parent process when apache restart occurs.&lt;/li&gt;
&lt;li&gt;No Saving in memory usage from copy on write&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;when the interpreter is destroyed combined with the way in which Apache reloads mod_wsgi when restarting the python interpreter will leak memory into the Apache parent process if Apache restarts have done on a regular basis the size of the Apache process will grow over time and thus so will the forked worker processes effectively have a memory leak.&lt;/p&gt;

&lt;h3&gt;
  
  
  Handling large number of clients
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;MaxClients 256&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The only reason that the default for Apache specifies such a large value for max clients and thus a  large number of processes when threading is used is because of slow clients and keep-alive, a high number is required to support concurrent session from many users if using single threaded processes this means, there should be much more memory available.&lt;/p&gt;

&lt;p&gt;A much better solution is to put is Nginx proxy in front of Apache, the nginx server will isolate apache from slow clients as a leaning forwarded request, when it is completely available and can be handled immediately the nginx server can also handle keep-alive connections, then keep-alive can be turned off on apache, this will allow us to significantly reduce the number of processes needded for Apache to handle the same ammount of traffic as before.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making Apache Suck Less - 3
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Set MaxSpareProcesses at a Level above the typical number of concurrent requests you would need to handle.&lt;/li&gt;
&lt;li&gt;Do not use MaxRequestsPerChild, especially at a low count which would cause frequent process churn.&lt;/li&gt;
&lt;li&gt;Remember that if you don't set MaxRequestsPerChild explicitly, it defaults to 10000.&lt;/li&gt;
&lt;li&gt;Use nginx as front-end proxy to isolate Apache from slow clients.&lt;/li&gt;
&lt;li&gt;Turn off Keep-Alive in apache when using nginx  front-end.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Making Apache Such Less - 4
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure MaxSpareThreads is at least MinSpareThread+ThreadsPerChild.If you don't, Apache will set it to that for you anyway.&lt;/li&gt;
&lt;li&gt;Suggested that MinSpareThreads and MaxSpareThreads be set as Multiples of ThreadsPerChild&lt;/li&gt;
&lt;li&gt;Don't set StartServers to be less thab MinSpareThreads/ThreadsPerChild as it will delay start up of processes so as to reach minimum spare required.&lt;/li&gt;
&lt;li&gt;Don't set StartServers to be greater than MaxSpareThreads/ThreadsPerChild as Processes will start to be killed off immediately.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Reducing Per Thread Memory Use
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;MaxMemFree - Maximum amount of memory that the main allocator is allowed to hold without calling free()&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;MaxMemFree   256  # KB&lt;/p&gt;

&lt;p&gt;2.4 --&amp;gt; MB&lt;/p&gt;

&lt;p&gt;Even at 2 MB in Apache 2. this could mean that 25 threads &amp;gt;&amp;gt;&amp;gt; 50 MB can be hold by the persistent memory pools at eash process when running mod_wsgi and normal circumstances this should not be much call for memory to be allocated from the per request memory pool.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making Apache Such Less -5
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ensure that MaxMemFree is set and not left to be unbounded.&lt;/li&gt;
&lt;li&gt;Even on Apache2.4 where is 2MB, consider reducing the value further.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Daemon Mode of Apache/mod_wsgi
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://community.ops.io/images/Qxc5Z3s8eZNGUW6vnuh0GIyG_IWudaGdC8XwdInxgvg/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvYWsx/c2tqaHpwYTQzeGdj/ZW4xeWsucG5n" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/Qxc5Z3s8eZNGUW6vnuh0GIyG_IWudaGdC8XwdInxgvg/w:880/mb:500000/ar:1/aHR0cHM6Ly9kZXYt/dG8tdXBsb2Fkcy5z/My5hbWF6b25hd3Mu/Y29tL3VwbG9hZHMv/YXJ0aWNsZXMvYWsx/c2tqaHpwYTQzeGdj/ZW4xeWsucG5n" alt="Alt Text" width="880" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the configuration for frefork or worker MPM are princiapply an issue when using ehat is called embedded mode of mod_wsgi, that is wsgi application runs inside of the Apache server child processes, the dynamics scaling algorithm in Apache being what can cause us grief when doing this.&lt;/p&gt;

&lt;p&gt;Use mod_wsgi Daemon mode in this case wsgi application runs in a separate set of managed proccesses the main difference when using daemon mode is that there is no automatic scaling on the number of processes, the number of processes and the thread is instead fixed, being fixed everything is more predictable and then you only need to ensure you have sufficient resources, using daemon mode the need to have nginx as frontend proxy is reduced as the apache server child worker process are serving much the same purpose in isolating wsgi application from the clients.&lt;/p&gt;

&lt;p&gt;Because the apache server process is now only acting as proxy forwarding request to the mod_wsgi daemon mode process as well as serving static files we don't need to initialize the python interpreter in the Apache server processes.&lt;/p&gt;

&lt;p&gt;Process creation is again lightweight and we have to sidestep the need to have to pay so much attention to the apache MPM settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuration :
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WSGIDaemonProcess myapp processes=3 threads=5

WSGIScriptAlias / /some/path/wsgi.py  process-group=myapp application-group=%{GLOBAL}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Exclusively Using Daemon Mode:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;WSGIRestrictedEmbedded - Controls whether the Python interpreter is initialised in Apache server worker processes.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;WSGIRestrictedEmbedded On&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  The thing that make Apache Suck
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;An algorithm for dynamically scaling processes which isn't particularly suited to embedded Python web applications.&lt;/li&gt;
&lt;li&gt;Default MPM settings which magnify the issues which can arise with dynamic scaling when running python web applications.&lt;/li&gt;
&lt;li&gt;A concurrency mechanism that can use a lot of memory for a higher of concurrent requests,especially around handling of keep alive connections.&lt;/li&gt;
&lt;li&gt;Defaults for memory pool sizes which cause Apache to be heavyweight on memory usage&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Conclusion :
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Use daemon mode.&lt;/li&gt;
&lt;li&gt;Disable embedded mode using &lt;code&gt;WSGIRestrictEmbedded On&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Use at most 5 threads per process, unless excessively I/O bound.&lt;/li&gt;
&lt;li&gt;Use processes over threads, but don't get carried away with processes either.&lt;/li&gt;
&lt;li&gt;Scale across multiple machines.&lt;/li&gt;
&lt;li&gt;Instrument the WSGI server and application so now how it performs for real system.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;References: &lt;br&gt;
&lt;a href="https://youtu.be/k6Erh7oHvns"&gt;https://youtu.be/k6Erh7oHvns&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>tutorials</category>
    </item>
    <item>
      <title>Harden Apache2 Server</title>
      <dc:creator>Tikam Alma</dc:creator>
      <pubDate>Wed, 25 May 2022 20:23:54 +0000</pubDate>
      <link>https://community.ops.io/tikam_alma/harden-apache2-server-10k0</link>
      <guid>https://community.ops.io/tikam_alma/harden-apache2-server-10k0</guid>
      <description>&lt;p&gt;&lt;a href="https://community.ops.io/images/7sFWhr07CXWrn0Dv8bZ58mAJdrSi0E2e2LCnuKc6NBA/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL3pkb2g4/NnFzcGs0YnJ0Mzl5/NHcyLnBuZw" class="article-body-image-wrapper"&gt;&lt;img src="https://community.ops.io/images/7sFWhr07CXWrn0Dv8bZ58mAJdrSi0E2e2LCnuKc6NBA/w:880/mb:500000/ar:1/aHR0cHM6Ly9jb21t/dW5pdHkub3BzLmlv/L3JlbW90ZWltYWdl/cy91cGxvYWRzL2Fy/dGljbGVzL3pkb2g4/NnFzcGs0YnJ0Mzl5/NHcyLnBuZw" alt="Image description" width="722" height="916"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Install Mod_Security2
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;libapache2-mod-security2 &lt;span class="nt"&gt;-y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Alternatively install from Github official repository&lt;/p&gt;

&lt;p&gt;[&lt;a href="https://github.com/SpiderLabs/ModSecurity(https://github.com/SpiderLabs/ModSecurity)"&gt;https://github.com/SpiderLabs/ModSecurity(https://github.com/SpiderLabs/ModSecurity)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After installing ModSecurity, enable the Apache 2 &lt;code&gt;headers&lt;/code&gt; module :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;a2enmod headers
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installing ModSecurity and enabling the header module,restart the apache2 service :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;    &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Get OWASP CRS and Configure it
&lt;/h3&gt;

&lt;p&gt;ModSecurity is a firewall and therefore requires rules to function.&lt;/p&gt;

&lt;p&gt;So we add the OWASP's CRS - Core Rule Set to harden our server&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove the default .recommended extension from the ModSecurity configuration file name
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo cp&lt;/span&gt; /etc/modsecurity/modsecurity.conf-recommended /etc/modsecurity/modsecurity.con
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;With a text editor such as vim, open /etc/modsecurity/modsecurity.conf and change the value for SecRuleEngine to On:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /etc/modsecurity/modsecurity.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SecRuleEngine On
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart Server&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The OWASP ModSecurity Core Rule Set (CRS) is a set of generic attack detection rules for use with ModSecurity or compatible web application firewalls. The CRS aims to protect web applications from a wide range of attacks, including the OWASP Top Ten, with a minimum of false alerts. The CRS provides protection against many common attack categories, including SQL Injection, Cross Site Scripting, and Local File Inclusion.&lt;/p&gt;

&lt;p&gt;To set up the OWASP-CRS, follow the procedures outlined below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;First, delete the current rule set that comes prepackaged with ModSecurity by running the following command:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; /usr/share/modsecurity-crs
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ensure that git is installed:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;git
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Clone the OWASP-CRS GitHub repository into the &lt;code&gt;/usr/share/modsecurity-crs&lt;/code&gt; directory:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;git clone https://github.com/coreruleset/coreruleset /usr/share/modsecurity-crs
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rename the &lt;code&gt;crs-setup.conf.example&lt;/code&gt; to &lt;code&gt;crs-setup.conf&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mv&lt;/span&gt; /usr/share/modsecurity-crs/crs-setup.conf.example /usr/share/modsecurity-crs/crs-setup.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rename the default request exclusion rule file:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo mv&lt;/span&gt; /usr/share/modsecurity-crs/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example /usr/share/modsecurity-crs/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You should now have the OWASP-CRS setup and ready to be used in your Apache configuration.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Configure your server  to use Mod_security
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt; Edit the /etc/apache2/mods-available/security2.conf file to include the OWASP-CRS
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /etc/apache2/mods-available/security2.conf

&amp;lt;IfModule security2_module&amp;gt;
        SecDataDir /var/cache/modsecurity
        Include /usr/share/modsecurity-crs/crs-setup.conf
        Include /usr/share/modsecurity-crs/rules/&lt;span class="k"&gt;*&lt;/span&gt;.conf
&amp;lt;/IfModule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Include the SecRuleEngine directive set to On.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;to /etc/apache2/your.website.conf

&amp;lt;VirtualHost &lt;span class="k"&gt;*&lt;/span&gt;:80&amp;gt;
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        ErrorLog &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APACHE_LOG_DIR&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/error.log
        CustomLog &lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;APACHE_LOG_DIR&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;/access.log combined

        SecRuleEngine On
&amp;lt;/VirtualHost&amp;gt;

Or

&amp;lt;IfModule security2_module&amp;gt;
SecRuleEngine On
&amp;lt;/IfModule&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Restart the apache2 service to apply the configuration
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Testing ModSecurity
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://&amp;lt;SERVER-IP/DOMAIN&amp;gt;/index.php?exec&lt;span class="o"&gt;=&lt;/span&gt;/bin/bash

You&lt;span class="s1"&gt;'ll get 404
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Enabling HTTP Policy and Paranoia
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;to /usr/share/modsecurity-crs

&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /usr/share/modsecurity-crs
or
&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /usr/share/modsecurity-crs/crs-setup.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Change Paranoia Level  on Paranoia Level Initialization section.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Find this section on&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/usr/share/modsecurity-crs/crs-setup.conf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;[[ Paranoia Level Initialization ]] &lt;/p&gt;

&lt;p&gt;The Paranoia Level (PL) setting allows you to choose the desired level of rule checks that will add to your anomaly scores.With each paranoia level increase, the CRS enables additional rules giving you a higher level of security. However, higher paranoia levels also increase the possibility of blocking some legitimate traffic due to false alarms (also named false positives or FPs). If you use higher paranoia levels, it is likely that you will need to add some exclusion rules for certain requests and applications receiving complex input.&lt;/p&gt;

&lt;h3&gt;
  
  
  A paranoia level of 1 is default.
&lt;/h3&gt;

&lt;p&gt;In this level, most core rules are enabled. PL1 is advised for beginners, installations covering many different sites and applications, and for setups with standard security requirements.At PL1 you should face FPs rarely. If you encounter FPs, please open an issue on the CRS GitHub site and don't forget to attach your complete Audit Log record for the request with the issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Paranoia level 2
&lt;/h3&gt;

&lt;p&gt;This level Includes many extra rules, for instance enabling many regexp-based SQL and XSS injection protections, and adding extra keywords checked for code injections. PL2 is advised for moderate to experienced users desiring more complete coverage and for installations with elevated security requirements. PL2 comes with some FPs which you need to handle.&lt;/p&gt;

&lt;h3&gt;
  
  
  Paranoia level 3
&lt;/h3&gt;

&lt;p&gt;It enables more rules and keyword lists, and tweaks limits on special characters used. PL3 is aimed at users experienced at the handling of FPs and at installations with a high security requirement.&lt;/p&gt;

&lt;h3&gt;
  
  
  Paranoia level 4
&lt;/h3&gt;

&lt;p&gt;It further restricts special characters.The highest level is advised for experienced users protecting installations with very high security requirements. Running PL4 will likely produce a very high number of FPs which have to be treated before the site can go productive.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SecAction &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s2"&gt;"id:900000,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
phase:1,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
nolog,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
pass,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
t:none,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
setvar:tx.paranoia_level=1"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. HTTP Policy Settings on HTTP Policy Settings Section
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;nano /usr/share/modsecurity-crs/crs-setup.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Section on - [[ HTTP Policy Settings ]] &lt;/p&gt;

&lt;p&gt;This section defines your policies for the HTTP protocol, such as: allowed HTTP versions, HTTP methods, allowed request Content-Types forbidden file extensions (e.g. .bak, .sql) and request headers (e.g. Proxy)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;These variables are used in the following rule files:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;REQUEST-911-METHOD-ENFORCEMENT.conf&lt;/p&gt;

&lt;p&gt;REQUEST-912-DOS-PROTECTION.conf&lt;/p&gt;

&lt;p&gt;REQUEST-920-PROTOCOL-ENFORCEMENT.conf&lt;/p&gt;

&lt;p&gt;HTTP methods that a client is allowed to use.&lt;/p&gt;

&lt;p&gt;Default: GET HEAD POST OPTIONS&lt;/p&gt;

&lt;p&gt;Example: for RESTful APIs, add the following methods: PUT PATCH DELETE&lt;/p&gt;

&lt;p&gt;Example: for WebDAV, add the following methods: CHECKOUT COPY DELETE LOCK&lt;/p&gt;

&lt;p&gt;MERGE MKACTIVITY MKCOL MOVE PROPFIND PROPPATCH PUT UNLOCK&lt;/p&gt;

&lt;p&gt;Uncomment this rule to change the default.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SecAction &lt;span class="se"&gt;\&lt;/span&gt;
&lt;span class="s2"&gt;"id:900200,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
phase:1,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
nolog,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
pass,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
t:none,&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
setvar:'tx.allowed_methods=GET HEAD POST OPTIONS PUT PATCH DELETE'"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>tutorials</category>
      <category>secops</category>
    </item>
    <item>
      <title>Configuring Domains and Sub-Domains in Apache webserver.</title>
      <dc:creator>Tikam Alma</dc:creator>
      <pubDate>Wed, 25 May 2022 20:00:56 +0000</pubDate>
      <link>https://community.ops.io/tikam_alma/configuring-domains-and-sub-domains-in-apache-webserver-1fdk</link>
      <guid>https://community.ops.io/tikam_alma/configuring-domains-and-sub-domains-in-apache-webserver-1fdk</guid>
      <description>&lt;h2&gt;
  
  
  What are the Sub-domains?Why are Domains and Sub-Domains required?
&lt;/h2&gt;

&lt;p&gt;Domains are well website name or the identity or a website, that one buys from a domain registrar website like google or GoDaddy and that is the address of your personal or professional website. &lt;br&gt;
And subdomains are the subset or part of a personal or professional website, where users can add and extend the main domain's functions and features.&lt;br&gt;
For example, a user wants to start his Food tech business and also wants to write blogs about food, and also wants to tracks the business transactions of his business.&lt;/p&gt;

&lt;p&gt;Each feature has different functionality on the application side, the calculation, tracking, and analysis on the dashboard, the text editor and content management for the blog, etc. &lt;/p&gt;

&lt;p&gt;Here, comes the subdomains part, why we need it. &lt;br&gt;
The user will create his home page on a different directory, blog features have different code and stores on the different directory and same for dashboard also, and now the apache webserver will be able to manage all these directories and able to handle the requests on domains and sub-domains using configuration on the virtual host.&lt;/p&gt;
&lt;h2&gt;
  
  
  Configuring VirtualHost to Enable Domains and Sub-Domains
&lt;/h2&gt;

&lt;p&gt;Change directory to the &lt;code&gt;/etc/apache2/&lt;/code&gt; and select the configuration file which you want to edit for adding subdomains.&lt;br&gt;
There must be two files one is &lt;code&gt;my-domain.conf&lt;/code&gt; and the other is default configuration &lt;code&gt;000-default.conf&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ sudo vi /etc/apache2/sites-available/my-domain.conf
OR 
$ sudo vi /etc/apache2/sites-available/000-default.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Add Wildcard Subdomain&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Home Page - mysite.com (Main Domain)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;VirtualHost *:80&amp;gt;
   DocumentRoot /var/www/home
   ServerName mysite.com
 &amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Blog Page - blog.mysite.com (Sub-Domain)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
   DocumentRoot /var/www/blog
   ServerName blog.mysite.com
 &amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dashboard - dashboard.mysite.com (Sub-domain)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
   DocumentRoot /var/www/dash
   ServerName dashboard.mysite.com
 &amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wildcard Domain&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;VirtualHost *:80&amp;gt;
     ServerAlias *.mysite.com
     DocumentRoot /var/www/html/wildcard/
 &amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Final Configuration&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## HomePage
 &amp;lt;VirtualHost *:80&amp;gt;
   DocumentRoot /var/www/home
   ServerName mysite.com
 &amp;lt;/VirtualHost&amp;gt;

## Blog Page
&amp;lt;VirtualHost *:80&amp;gt;
   DocumentRoot /var/www/blog
   ServerName blog.mysite.com
 &amp;lt;/VirtualHost&amp;gt;

## Dashboard Page
&amp;lt;VirtualHost *:80&amp;gt;
   DocumentRoot /var/www/dash
   ServerName dashboard.mysite.com
 &amp;lt;/VirtualHost&amp;gt;

## Wild Card
&amp;lt;VirtualHost *:80&amp;gt;
     ServerAlias *.mysite.com
     DocumentRoot /var/www/html/wildcard/
 &amp;lt;/VirtualHost&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing and Dry Run the Configuration
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Check the configuration by running the command:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sudo apachectl configtest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reload and Restart the server&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Reload
$ sudo service apache2 reload

# Restart
$ sudo service apache2 restart
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>tutorials</category>
      <category>devops</category>
      <category>cloudops</category>
    </item>
  </channel>
</rss>
