{"id":506,"date":"2016-01-25T11:56:35","date_gmt":"2016-01-25T09:56:35","guid":{"rendered":"http:\/\/www.systemcodegeeks.com\/?p=506"},"modified":"2018-06-08T11:06:42","modified_gmt":"2018-06-08T08:06:42","slug":"nginx-configuration-guide","status":"publish","type":"post","link":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/","title":{"rendered":"Nginx Configuration Guide (Ubuntu 12.04 LTS)"},"content":{"rendered":"<p><em>In this post, we feature a comprehensive Nginx Configuration Guide. This article is part of our Academy Course titled <a href=\"http:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/introduction-to-nginx-complete-tutorial\/\">Introduction to Nginx<\/a>.<\/em><\/p>\n<p>This course will introduce you to the magic of nginx. You will learn to install and configure nginx for a variety of software platforms and how to integrate it with Apache. Additionally, you will get involved with more advanced concepts like Load Balancing, SSL configuration and Websockets proxying. Check it out <a href=\"http:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/introduction-to-nginx-complete-tutorial\/\">here<\/a>!<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;O5wwlXQPIiCQp2ED&#8217;]<\/p>\n<div class=\"toc\">\n<h4>Table Of Contents<\/h4>\n<dl>\n<dt><a href=\"#configuration\">1. Configuration file syntax<\/a><\/dt>\n<dt><a href=\"#directives\">2. Configuration directives<\/a><\/dt>\n<dt><a href=\"#organization\">3. Organization and inclusions<\/a><\/dt>\n<dt><a href=\"#basemodules\">4. Base modules<\/a><\/dt>\n<dt><a href=\"#httpserver\">5. The HTTP Server<\/a><\/dt>\n<dt><a href=\"#mailserverproxy\">6. Mail server proxy<\/a><\/dt>\n<dt><a href=\"#virtualhosts\">7. Virtual hosts<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"configuration\"><\/a>1. Configuration file syntax<\/h2>\n<p>According to Merriam-Websters online dictionary, the word syntax represents \u201cthe way in which words are put together to form phrases, clauses, or sentences\u201d. Of course that definition, as it is taken from a dictionary, is aimed at English (or actually any other language) students. So what about IT people coming from all backgrounds, languages, and countries? The change in context does not alter the meaning of the term very significantly. In particular, the syntax of a configuration file must be correct, as seen by the program that will parse it, in order for it to work efficiently.<\/p>\n<p>We will learn to understand and how to write (and \/ or modify) a configuration file for Nginx under Ubuntu 12.04 LTS. That will be accomplished by specifying a set of values that will define the behavior of the web server.<\/p>\n<h2><a name=\"directives\"><\/a>2. Configuration directives<\/h2>\n<p>By default, the behavior of Nginx is defined by its main configuration file, which is located (as seen before and unless we have modified this setting) at <code>\/usr\/local\/nginx\/conf\/nginx.conf<\/code>. This file is composed of a list of directives organized in a logical structure that is very easy to follow and understand (see Fig. 1).<\/p>\n<figure id=\"attachment_2835\" aria-describedby=\"caption-attachment-2835\" style=\"width: 670px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/001_1.png\"><img decoding=\"async\" class=\"wp-image-2835 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/001_1.png\" alt=\"Nginx Configuration Guide: 001_1\" width=\"670\" height=\"515\" \/><\/a><figcaption id=\"caption-attachment-2835\" class=\"wp-caption-text\">Figure 1: Nginx main configuration file (nginx.conf)<\/figcaption><\/figure>\n<p>The lines that begin with \u201c#\u201d are comments, or in other words, strings of text that are not interpreted by the program during execution. You can comment out entire lines or add brief comments after a line to clarify what it is supposed to do.<\/p>\n<p>The next line shows a directive, in this case <code>worker_processes<\/code>, which represents a setting to which we will append one or more values, depending on its syntax. Actually, the <code>worker_processes<\/code> directive only accepts one argument, which needs to be a numerical value. Another example of a directive is <code>user<\/code> (which is commented out in the previous line). The <code>user<\/code> directive lets us add up to 2 text strings \u2013 the first one is required and indicates the user account Nginx will run as, and the second one is optional (user group). We will need to remember, right from the start, that each directive has its own meaning and defines a particular feature of the application.<\/p>\n<p>Each module that is part of Nginx has a specific set of directives. When a new module is activated, its specific set of directives becomes available, and directive blocks may also be enabled.<\/p>\n<p>Directive blocks are precisely that: a block of text that lets us specify a logical construction of the configuration and allows us to use inheritance, which means that configuration found in a certain block is passed on to its children blocks as well. However, inside a children block you can still change the value of a directive that was defined in its parent block.<\/p>\n<p>In Fig. 2a and 2b we see that all access to the root directory of the site (\/) is saved to <code>\/home\/gacanepa\/nginx-1.5.6\/html\/access_log<\/code> except for the access to the directory named restricted (notice the directive <code>access_log off<\/code>) in the corresponding directive block.<\/p>\n<figure id=\"attachment_2836\" aria-describedby=\"caption-attachment-2836\" style=\"width: 935px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/002a_1.png\"><img decoding=\"async\" class=\"wp-image-2836 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/002a_1.png\" alt=\"Nginx Configuration Guide: 002a_1\" width=\"935\" height=\"354\" \/><\/a><figcaption id=\"caption-attachment-2836\" class=\"wp-caption-text\">Figure 2a: Nested directive blocks<\/figcaption><\/figure>\n<figure id=\"attachment_2837\" aria-describedby=\"caption-attachment-2837\" style=\"width: 1094px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/002b_1.png\"><img decoding=\"async\" class=\"wp-image-2837 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/002b_1.png\" alt=\"Nginx Configuration Guide: 002b_1\" width=\"1094\" height=\"410\" \/><\/a><figcaption id=\"caption-attachment-2837\" class=\"wp-caption-text\">Figure 2b: Access logs&lt;&gt;<\/figcaption><\/figure>\n<h2><a name=\"organization\"><\/a>3. Organization and inclusions<\/h2>\n<p>Let\u2019s focus on line 17. There is a special directive there: <code>include<\/code>. This directive is used to insert the contents of the specified file at this exact location. The name of the file can be specified either by an absolute path or a relative path to the current directory (as it is in this case). We can see that there\u2019s a file named <code>mime.types<\/code> in the same directory as <code>nginx.conf<\/code> (see Fig. 3).<\/p>\n<figure id=\"attachment_2838\" aria-describedby=\"caption-attachment-2838\" style=\"width: 804px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx_conf_dir.png\"><img decoding=\"async\" class=\"wp-image-2838 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx_conf_dir.png\" alt=\"Nginx Configuration Guide: nginx_conf_dir\" width=\"804\" height=\"400\" \/><\/a><figcaption id=\"caption-attachment-2838\" class=\"wp-caption-text\">Figure 3<\/figcaption><\/figure>\n<p>The end result is the same that would be accomplished by actually inserting the contents of <code>mime.types<\/code> into the <code>nginx.conf<\/code> file. Of course, if we do that, the main configuration file would soon become a nightmare to read. This way the include directive helps us to ensure that the <code>nginx.conf<\/code> file remains easy to read and understand. As a plus, it works recursively in that an included file can reference another file and so on, and it also supports <code>filename globbing<\/code>, which means it recognizes and expands the standard wild card characters (* and ?) and character lists in square brackets, for example. This way we can add multiple configuration files such as <code>20131030.conf<\/code>, <code>20131031.conf<\/code>, and <code>20131101.conf<\/code>. If we only want to include the files that begin with 201310, we must add the following line to the <code>nginx.conf<\/code> file (see Fig. 4):<\/p>\n<figure id=\"attachment_2839\" aria-describedby=\"caption-attachment-2839\" style=\"width: 615px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/004_1.png\"><img decoding=\"async\" class=\"wp-image-2839 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/004_1.png\" alt=\"Nginx Configuration Guide: 004_1\" width=\"615\" height=\"185\" \/><\/a><figcaption id=\"caption-attachment-2839\" class=\"wp-caption-text\">Figure 4: Including files using wildcards<\/figcaption><\/figure>\n<p>However, if we add a specific file (not by <code>filename globbing<\/code>) that doesn\u2019t exist, Nginx will not start properly (see Fig. 5a). Otherwise, we will be presented with a \u201ctest is successful\u201d message (see Fig. 5b):<\/p>\n<figure id=\"attachment_2840\" aria-describedby=\"caption-attachment-2840\" style=\"width: 1094px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/005_1.png\"><img decoding=\"async\" class=\"wp-image-2840 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/005_1.png\" alt=\"Nginx Configuration Guide: 005_1\" width=\"1094\" height=\"170\" \/><\/a><figcaption id=\"caption-attachment-2840\" class=\"wp-caption-text\">Figure 5a: Nginx fails to restart due to a missing include file<\/figcaption><\/figure>\n<figure id=\"attachment_2841\" aria-describedby=\"caption-attachment-2841\" style=\"width: 1040px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/005b_1.png\"><img decoding=\"async\" class=\"wp-image-2841 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/005b_1.png\" alt=\"Nginx Configuration Guide: 005b_1\" width=\"1040\" height=\"150\" \/><\/a><figcaption id=\"caption-attachment-2841\" class=\"wp-caption-text\">Figure 5b: The syntax test of the configuration file has completed successfully<\/figcaption><\/figure>\n<h2><a name=\"basemodules\"><\/a>4. Base modules<\/h2>\n<p>The base modules allow us to define the basic parameters and configuration of Nginx. They are built-in into Nginx automatically during compile time. Their directives and blocks are always available. There are three types of base modules:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>The <strong><em>core<\/em><\/strong> module contains essential directives and features. Most of its directives must be placed at the root (meaning the top) of the configuration file and are only used once. Table 1 shows some directives in the core module with a brief explanation and context (if no context is specified, the actual context is global and the directive must be placed at the root of the configuration file).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<div class=\"wp-caption aligncenter\">\n<table border=\"2\">\n<tbody>\n<tr>\n<td><strong>Directive\/Context<\/strong><\/td>\n<td><strong>Syntax and description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><code>daemon<\/code><\/td>\n<td>Accepted values: on \/ off<br \/>\nSyntax: daemon on;<br \/>\nEnables or disables daemon mode (starts the program in the background or the foreground, respectively). Useful to troubleshoot issues.<\/td>\n<\/tr>\n<tr>\n<td><code>env<\/code><\/td>\n<td>Syntax: <code>env MY_VARIABLE=my_value;<\/code><br \/>\nAllows us to define or define environment variables.<\/td>\n<\/tr>\n<tr>\n<td><code>error_log<\/code><\/td>\n<td>Context: <code>main, http, server<\/code>, and <code>location<\/code> Syntax: <code>error_log \/path\/to\/file level<\/code> (where level can be one of the following values: debug, info, notice, warn, error, and crit, depending on the type of errors that we want to save in the log file). To disable error logging, redirect the log output to \/dev\/null:<br \/>\n<code>error_log \/dev\/null crit;<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>master_process<\/code><\/td>\n<td>Accepted values: <code>on \/ off<\/code><br \/>\nDefault value: <code>on<\/code><br \/>\nIf enabled (on) Nginx will start both the master process and worker processes. If disabled, Nginx will work with a unique process. This is used for debugging purposes only and will cause that clients won\u2019t be able to connect to the server.<\/td>\n<\/tr>\n<tr>\n<td><code>pid<\/code><\/td>\n<td>Syntax: <code>file path<\/code><br \/>\nDefault value: defined at compile time.<br \/>\nPath of the file where the PID of Nginx will be stored.<\/td>\n<\/tr>\n<tr>\n<td><code>user<\/code><\/td>\n<td>Syntax: <code>user username groupname;<\/code><br \/>\n<code>user username;<\/code><br \/>\nLets you define the user account, and optionally the user group used for starting the worker processes. For security reasons, a user \/ group with limited privileges must be used for this.<\/td>\n<\/tr>\n<tr>\n<td><code>worker_processes<\/code><\/td>\n<td>Syntax: <code>numeric<\/code> or <code>auto<\/code>, for example:<br \/>\n<code>worker_processes 4;<\/code><br \/>\nDefines the amount of worker processes. If a process is blocked for some reason, future requests can be served by other worker processes. If the value auto is used, Nginx selects an appropriate value (which by default it is the amount of CPU cores detected).<\/td>\n<\/tr>\n<tr>\n<td><code>worker_priority<code><\/code><\/code><\/td>\n<td>Syntax: <code>Numeric<\/code><br \/>\n<code>worker_priority 0;<\/code><br \/>\nDefines the priority, as the operating system sees it, of the worker processes from -20 (highest) to 19 (lowest).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"wp-caption-text\">Table 1: Some Core Module directives<\/p>\n<\/div>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>The <strong><em>events<\/em><\/strong> module allows us to configure the operation of the networking capabilities of Nginx. These directives must be placed inside the events block at the root of the configuration file (see Fig. 6). Table 2 shows two of the directives available in this module.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<figure id=\"attachment_2842\" aria-describedby=\"caption-attachment-2842\" style=\"width: 651px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/006_1.png\"><img decoding=\"async\" class=\"wp-image-2842 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/006_1.png\" alt=\"Nginx Configuration Guide: 006_1\" width=\"651\" height=\"225\" \/><\/a><figcaption id=\"caption-attachment-2842\" class=\"wp-caption-text\">Figure 6: The events block<\/figcaption><\/figure>\n<div class=\"wp-caption aligncenter\">\n<table border=\"2\">\n<tbody>\n<tr>\n<td><strong>Directive\/Context<\/strong><\/td>\n<td><strong>Syntax and description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><code>worker_connections<\/code><\/td>\n<td>Syntax: <code>Numeric<\/code><br \/>\nDefines the amount of connections that a worker process may handle simultaneously.<\/td>\n<\/tr>\n<tr>\n<td><code>debug_connection<\/code><\/td>\n<td>Syntax: IP address or CIDR block.<br \/>\n<code>debug_connection 192.168.0.100<\/code><br \/>\n<code>debug_connection 192.168.0.0\/24<\/code><br \/>\nWrites detailed log for clients matching this IP address or CIDR block. The information is saved in the file defined in the <code>error_log<\/code> directive (it must be enabled with the debug level, and Nginx must be compiled with the <code>--debug<\/code> switch in order to enable this directive).<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p class=\"wp-caption-text\">Table 2: Some Events Module directives<\/p>\n<\/div>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>The <strong><em>configuration<\/em><\/strong> module enables file inclusions with the include directive, as discussed earlier. The directive may be placed anywhere in the configuration file and accepts one (and only one) parameter: the file\u2019s path relative to the current working directory (unless it is specified with the path all the way down from the \/ directory).<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2><a name=\"httpserver\"><\/a>5. The HTTP Server<\/h2>\n<p>The web server itself is configured using the directives found in the HTTP Core module. This module is the essential component of the HTTP configuration and will allow us \u2013among other things- to serve multiple websites, which are referred to as virtual hosts. It is organized into three major blocks (see Fig. 7):<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li><strong>http:<\/strong> must be placed at the root of the configuration file. It is used to define directives and blocks related to the web server functionality of Nginx.<\/li>\n<li><strong>server:<\/strong> must be inserted inside the http block and is used to declare a specific website.<\/li>\n<li><strong>location:<\/strong> allows us to define a group of settings to be applied to certain sections of the web site. This block can either be used within a server block or nested inside another location block.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<figure id=\"attachment_2843\" aria-describedby=\"caption-attachment-2843\" style=\"width: 788px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/007_1.png\"><img decoding=\"async\" class=\"wp-image-2843 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/007_1.png\" alt=\"Nginx Configuration Guide: 007_1\" width=\"788\" height=\"506\" \/><\/a><figcaption id=\"caption-attachment-2843\" class=\"wp-caption-text\">Figure 7: The http, server, and location blocks<\/figcaption><\/figure>\n<h2><a name=\"mailserverproxy\"><\/a>6. Mail server proxy<\/h2>\n<p>To act as mail server (not enabled by default), Nginx must be compiled with the <code>--with-mail<\/code> (which enables mail server proxy module with support for POP3, IMAP4, and SMTP) option in <code>.\/configure<\/code>. If for some reason this will be the only use of Nginx in our system, the HTTP Core module can be disabled using the <code>--without-http switch<\/code>.<\/p>\n<p>In Fig. 8 we can see a portion of the mail block, which is used to set the configuration of the mail server. The capabilities of the imap, pop3, and smtp protocols and a detailed description can be found in the IANA (Internet Assigned Numbers Authority) web site.<\/p>\n<figure id=\"attachment_2844\" aria-describedby=\"caption-attachment-2844\" style=\"width: 801px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/008_1.png\"><img decoding=\"async\" class=\"wp-image-2844 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/008_1.png\" alt=\"Nginx Configuration Guide: 008_1\" width=\"801\" height=\"535\" \/><\/a><figcaption id=\"caption-attachment-2844\" class=\"wp-caption-text\">Figure 8: The mail block<\/figcaption><\/figure>\n<h2><a name=\"virtualhosts\"><\/a>7. Virtual hosts<\/h2>\n<p>As mentioned earlier, a virtual host is a certain website that is served by Nginx in a single server.<br \/>\nThe first step to set up virtual hosts is to create one or more server blocks in the main configuration file. Those server blocks are identified either by a hostname or through a combination or IP address and port number (see Fig. 9).<\/p>\n<figure id=\"attachment_2845\" aria-describedby=\"caption-attachment-2845\" style=\"width: 797px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/009_1.png\"><img decoding=\"async\" class=\"wp-image-2845 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/009_1.png\" alt=\"Nginx Configuration Guide: 009_1\" width=\"797\" height=\"299\" \/><\/a><figcaption id=\"caption-attachment-2845\" class=\"wp-caption-text\">Figure 9: Creating a server block to serve a virtual host<\/figcaption><\/figure>\n<p>Next, we need to set up the virtual host main configuration file. The default installation of Nginx provides a sample file (located in <code>\/etc\/nginx\/sites-available\/default<\/code>) that we will copy and name after our website:<\/p>\n<pre class=\"brush:bash\">sudo cp \/etc\/nginx\/sites-available\/default \/etc\/nginx\/sites-available\/nginxtest.com<\/pre>\n<p>Then the next thing to do is edit the sample file (<code>nginxtest.com<\/code>) with basically the same information that is found in the <code>nginx.conf<\/code> file (see Fig. 10).<\/p>\n<figure id=\"attachment_2846\" aria-describedby=\"caption-attachment-2846\" style=\"width: 200px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/010_1.png\"><img decoding=\"async\" class=\"wp-image-2846 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2017\/02\/Nagios-Monitoring-Handbook_wp.jpg\" alt=\"Nginx Configuration Guide: 010_1\" width=\"200\" height=\"296\" \/><\/a><figcaption id=\"caption-attachment-2846\" class=\"wp-caption-text\">Figure 10: Virtual host configuration file<\/figcaption><\/figure>\n<p>The virtual host must now be enabled by creating a symlink to this file in the <code>sites-enabled<\/code> directory:<\/p>\n<pre class=\"brush:bash\">sudo ln -s \/etc\/nginx\/sites-available\/example.com \/etc\/nginx\/sites-enabled\/nginxtest.com<\/pre>\n<p>To avoid conflicts, we can also delete the file named default in the sites-enabled directory:<\/p>\n<pre class=\"brush:bash\">sudo rm \/etc\/nginx\/sites-enabled\/default<\/pre>\n<p>Now let\u2019s restart Nginx and look what happens! (Fig. 11)<\/p>\n<figure id=\"attachment_2847\" aria-describedby=\"caption-attachment-2847\" style=\"width: 768px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/011_1.png\"><img decoding=\"async\" class=\"wp-image-2847 size-full\" src=\"http:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/011_1.png\" alt=\"Nginx Configuration Guide: 011_1\" width=\"768\" height=\"358\" \/><\/a><figcaption id=\"caption-attachment-2847\" class=\"wp-caption-text\">Figure 11: Our first virtual host is working<\/figcaption><\/figure>\n<p>To add more virtual hosts, we can just repeat the process above step by step, with the caution to set up a new document root with the appropriate domain name, and then creating and activating the new virtual host file as we did with the nginxtest.com website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we feature a comprehensive Nginx Configuration Guide. This article is part of our Academy Course titled Introduction to Nginx. This course will introduce you to the magic of nginx. You will learn to install and configure nginx for a variety of software platforms and how to integrate it with Apache. Additionally, you &hellip;<\/p>\n","protected":false},"author":15,"featured_media":195,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-506","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nginx"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Nginx Configuration Guide (Ubuntu 12.04 LTS) - System Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn more about Nginx Cofniguration? Then check out our detailed Nginx Configuration Guide where we will learn to understand and write (and \/ or modify) a configuration file for Nginx under Ubuntu 12.04 LTS.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Nginx Configuration Guide (Ubuntu 12.04 LTS) - System Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about Nginx Cofniguration? Then check out our detailed Nginx Configuration Guide where we will learn to understand and write (and \/ or modify) a configuration file for Nginx under Ubuntu 12.04 LTS.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/\" \/>\n<meta property=\"og:site_name\" content=\"System Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/systemcodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/gacanepa\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-25T09:56:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-08T08:06:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Gabriel Canepa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@gacanepa\" \/>\n<meta name=\"twitter:site\" content=\"@systemcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Gabriel Canepa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/\"},\"author\":{\"name\":\"Gabriel Canepa\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f\"},\"headline\":\"Nginx Configuration Guide (Ubuntu 12.04 LTS)\",\"datePublished\":\"2016-01-25T09:56:35+00:00\",\"dateModified\":\"2018-06-08T08:06:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/\"},\"wordCount\":1981,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg\",\"articleSection\":[\"NGINX\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/\",\"name\":\"Nginx Configuration Guide (Ubuntu 12.04 LTS) - System Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg\",\"datePublished\":\"2016-01-25T09:56:35+00:00\",\"dateModified\":\"2018-06-08T08:06:42+00:00\",\"description\":\"Interested to learn more about Nginx Cofniguration? Then check out our detailed Nginx Configuration Guide where we will learn to understand and write (and \/ or modify) a configuration file for Nginx under Ubuntu 12.04 LTS.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.systemcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Servers\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"NGINX\",\"item\":\"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/nginx\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Nginx Configuration Guide (Ubuntu 12.04 LTS)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#website\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"name\":\"System Code Geeks\",\"description\":\"Operating System Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.systemcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/systemcodegeeks\",\"https:\/\/x.com\/systemcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f\",\"name\":\"Gabriel Canepa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g\",\"caption\":\"Gabriel Canepa\"},\"description\":\"Gabriel Canepa is a Linux Foundation Certified System Administrator (LFCS-1500-0576-0100) and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. When he's not typing commands or writing code or articles, he enjoys telling bedtime stories with his wife to his two little daughters and playing with them, the great pleasure of his life.\",\"sameAs\":[\"http:\/\/www.gabrielcanepa.com.ar\/\",\"https:\/\/www.facebook.com\/gacanepa\",\"https:\/\/ar.linkedin.com\/in\/gacanepa\",\"https:\/\/x.com\/gacanepa\"],\"url\":\"https:\/\/www.systemcodegeeks.com\/author\/gabriel-canepa\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Nginx Configuration Guide (Ubuntu 12.04 LTS) - System Code Geeks - 2026","description":"Interested to learn more about Nginx Cofniguration? Then check out our detailed Nginx Configuration Guide where we will learn to understand and write (and \/ or modify) a configuration file for Nginx under Ubuntu 12.04 LTS.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/","og_locale":"en_US","og_type":"article","og_title":"Nginx Configuration Guide (Ubuntu 12.04 LTS) - System Code Geeks - 2026","og_description":"Interested to learn more about Nginx Cofniguration? Then check out our detailed Nginx Configuration Guide where we will learn to understand and write (and \/ or modify) a configuration file for Nginx under Ubuntu 12.04 LTS.","og_url":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/","og_site_name":"System Code Geeks","article_publisher":"https:\/\/www.facebook.com\/systemcodegeeks","article_author":"https:\/\/www.facebook.com\/gacanepa","article_published_time":"2016-01-25T09:56:35+00:00","article_modified_time":"2018-06-08T08:06:42+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg","type":"image\/jpeg"}],"author":"Gabriel Canepa","twitter_card":"summary_large_image","twitter_creator":"@gacanepa","twitter_site":"@systemcodegeeks","twitter_misc":{"Written by":"Gabriel Canepa","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#article","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/"},"author":{"name":"Gabriel Canepa","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f"},"headline":"Nginx Configuration Guide (Ubuntu 12.04 LTS)","datePublished":"2016-01-25T09:56:35+00:00","dateModified":"2018-06-08T08:06:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/"},"wordCount":1981,"commentCount":0,"publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg","articleSection":["NGINX"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/","url":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/","name":"Nginx Configuration Guide (Ubuntu 12.04 LTS) - System Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.systemcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage"},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage"},"thumbnailUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg","datePublished":"2016-01-25T09:56:35+00:00","dateModified":"2018-06-08T08:06:42+00:00","description":"Interested to learn more about Nginx Cofniguration? Then check out our detailed Nginx Configuration Guide where we will learn to understand and write (and \/ or modify) a configuration file for Nginx under Ubuntu 12.04 LTS.","breadcrumb":{"@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#primaryimage","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2016\/01\/nginx-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.systemcodegeeks.com\/web-servers\/nginx\/nginx-configuration-guide\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.systemcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Servers","item":"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/"},{"@type":"ListItem","position":3,"name":"NGINX","item":"https:\/\/www.systemcodegeeks.com\/category\/web-servers\/nginx\/"},{"@type":"ListItem","position":4,"name":"Nginx Configuration Guide (Ubuntu 12.04 LTS)"}]},{"@type":"WebSite","@id":"https:\/\/www.systemcodegeeks.com\/#website","url":"https:\/\/www.systemcodegeeks.com\/","name":"System Code Geeks","description":"Operating System Developers Resource Center","publisher":{"@id":"https:\/\/www.systemcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.systemcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.systemcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.systemcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.systemcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/systemcodegeeks","https:\/\/x.com\/systemcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/967da353d0f1a1de21c9504942625a5f","name":"Gabriel Canepa","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.systemcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/27b3ea2a3fb1de4ed1c8694a1465c099a86586d8b833a0d852a26d76d750df9f?s=96&d=mm&r=g","caption":"Gabriel Canepa"},"description":"Gabriel Canepa is a Linux Foundation Certified System Administrator (LFCS-1500-0576-0100) and web developer from Villa Mercedes, San Luis, Argentina. He works for a worldwide leading consumer product company and takes great pleasure in using FOSS tools to increase productivity in all areas of his daily work. When he's not typing commands or writing code or articles, he enjoys telling bedtime stories with his wife to his two little daughters and playing with them, the great pleasure of his life.","sameAs":["http:\/\/www.gabrielcanepa.com.ar\/","https:\/\/www.facebook.com\/gacanepa","https:\/\/ar.linkedin.com\/in\/gacanepa","https:\/\/x.com\/gacanepa"],"url":"https:\/\/www.systemcodegeeks.com\/author\/gabriel-canepa\/"}]}},"_links":{"self":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/506","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/comments?post=506"}],"version-history":[{"count":0,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/posts\/506\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media\/195"}],"wp:attachment":[{"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/media?parent=506"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/categories?post=506"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.systemcodegeeks.com\/wp-json\/wp\/v2\/tags?post=506"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}