Nginx

Nginx

Introduction

Nginx (pronounced “engine x”) is a web server with a strong focus on high concurrency, performance and low memory usage. It can also act as a reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a load balancer and an HTTP cache.

Created by Igor Sysoev in 2002, Nginx runs on Unix, Linux, BSD variants, Mac OS X, Solaris, AIX, HP-UX, and Microsoft Windows. Released under the terms of a BSD-like license, Nginx is free and open source software. (Source: Wikipedia)

Requirements

Sudo

Installation

sudo pkg install nginx

Configuration

sudo sysrc nginx_enable=YES
sudo service nginx start

Configuration File

When visiting username.it.pointpark.edu after completing the previous steps, you will be greeted with a generic nginx page stating:

Welcome to nginx! 

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

In order to properly direct a user to the desired target destination instead you must edit your nginx.conf file according to the file type you wish to direct to (ex. HTML, PHP, etc). This configuration file is located at:

sudo ee /usr/local/etc/nginx/nginx.conf

Depending on the location of your files in the directory structure, below is an example of what should be added to the conf file to direct to index.html under the http section.

    server {
        # name of your server
        listen       80;
        server_name  $USERNAME.it.pointpark.edu;
        
        # location of the root directory
        #
        location / {
            root   /home/$USERNAME/www;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
    }

In the above example server_name refers to the location of your jail. Replace $USERNAME with your own username (ex. mvoortman.it.pointpark.edu). Root refers the the directory which contains the html you are attempting to direct to. Index refers to the name of the file to be displayed in the web browser.

Refer to the further reading section to see a more complete example including php in addition to html.

References

Nginix Configuration
Sample nginx.conf file
Nginx at Wikipedia

Leave A Reply

Your email address will not be published.