Troubleshooters.Com®, Linux Library and T.C Nginx Essentials Present:
Build an Nginx Intro Server
Copyright © 2018 by Steve Litt
See the Troubleshooters.Com Bookstore.
CONTENTS
Nginx is a fast, lightweight, high performance web server that makes it easy to deploy websites. It has virtual web pages so you can have several websites at a single IP/port pair. With less features, it's easier to use.
Not much to say here. Nginx is very popular, so your distro will almost certainly have it in their package system.
Before installing Nginx, shut down any other web servers that may be active on your computer. They can all play well together later, but just to make things simple now, shut them down, if possible.
Find your distro's Nginx package and install it. For instance, on Devuan Jessie, perform the following command:
apt-get install nginx
The preceding command not only installs it, but sets up the init system (sysvinit in the case of Devuan) to install run it on boot, and also sets it running right now. On Void Linux, with the runit init system, it's a little different. First, perform the following command:
xbps-install nginx ln -s /etc/sv/nginx /var/service/nginx
The first command installs nginx in the init system, and the second runs it right now and makes sure it will run on boot.
Once Nginx is installed, incorporated with the init system, and running, browse to 127.0.0.1. If everything's working correctly, the following web page appears in your browser:
Once your browser shows the preceding page at http://127.0.0.1, you're done with installation. Now you can go ahead and specify a website.
Ask yourself this: Not counting the nature of the content, what information is necessary to specify a website? Answering this question requires thinking on a series of different levels.
The most basic level are those things that are necessary, and for which defaults cannot be made. These would include:
Without the first two of the preceding list, the website couldn't be found. Without the third, the website wouldn't know what content to serve.
The fourth setting, Character Set, has a useful default (off) for the purposes of a very simple learning website, so we'll use the default. In real life, the more your website departs from ASCII and English, the more you'll want to consider overriding this specification's default. If it becomes necessary, you can web-search settings for charset, charset_map, charset_types, override_charset, and source_charset.
Beyond the preceding list of four settings is information necessary to virtual hosts, which means packing multiple websites onto one IPaddress/port combination, according to domain name typed into the browser:
At a yet lower priority is whether you want to change the default for what page filename is the "index": Typically index.html and index.htm, but can also include index.php, index.xhtml or various other filenames.
Stepping down another level of importance is
With all of this in mind, the following is a reasonable entry level specification of a website,
server {
listen 192.168.47.189:80 default_server;
server_name mysite.cxm www.mysite.cxm;
location / {
root /websites/mysite;
index index.xhtml index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
This document has given you a tiny bit of nginx knowledge. To get more up close and personal with nginx, your next stop should be the Triple Site Example document.
[ Training | Troubleshooters.Com | Email Steve Litt ]