Installing a web server/Nginx web server

Installing Nginx web server
Nginx web server that was written in 2004 with an explicit goal of outperforming the traditional and widely used Apache web server. Official documentation is on https://nginx.org/en/docs/.
 * Configuration File:
 * Additional Configuration file:
 * Error log file:

Nginx vs Apache
Apache was first released in 1995 while Nginx was first released 9 years later in 2004, so traditionally there has been a more broad knowledge of Apache web server than Nginx. We will present main differences from Apache to Nginx for newcomers. Both servers support virtual host configuration and include directives.

Configuration differences

 * No concept equivalent to  files
 * Configuration file based on directives: vs , arguably Nginx configuration language is easier to read.

Installing and Operating Nginx web server on CentOS Linux
Installation packages for different Linux platforms is are available on Nginx linux package webpage. Follow this three easy steps on CentOS Linux:
 * 1) Update your package repository using http://nginx.org/en/linux_packages.html information
 * 2) run yum update
 * 3) sudo yum install -y nginx

Running Nginx web server

 * 1) Starting Nginx:

Check Nginx running

 * Check default webpage/virtualhost:
 * In case of error check error log file:


 * Check connection to example.com virtualhost:

Configuring Nginx
Configuration of Nginx on CentOS is done in /etc/nginx/nginx.conf (upstream github file )

Basic Nginx Operation

 * Check status:  (not output expected if everything runs properly)
 * Starting Nginx:  or
 * Stopping Nginx:
 * Reload configuration after every configuration change:, Nginx has to be reload every time we want any configuration change take effect.
 * Check Configuration:

Basic Nginx Configuration
Example of the simplest possible server configuration file, listening on 80 port (default http port)

/etc/nginx/conf.d/default.conf server { listen 80; root /usr/share/nginx/html; }

Example of the virtual host for www.example.com or example.com domain /etc/nginx/conf.d/default.conf server { listen 80; server_name example.com www.example.com root /var/www/example.com/html; }

Checking Nginx errors
Errors are write to error log file, you can use grep to search for errors. For example: grep error /var/log/nginx/error.log 2011/03/08 11:12:21 [error] 1755#1754 *8 "/var/www/example.com/html/index.html" is forbidden (13: Permission denied), client: 1.123.51.252, server: http://Example/URL.com, request: "GET / HTTP/1.1", host: "http://Example/URL.com" or grep emerg /var/log/nginx/error.log

Permission denied errors can be cause by Selinux security module misconfiguration, adding httpd_sys_content_t context can solve permission denied errors. semanage fcontext -a -t httpd_sys_content_t "/var/www(/.*)?" semanage fcontext -l | grep /var/www restorecon -R -v /var/www

Next Steps
Now you can check official documentation and learn how to
 * Modify default error pages using error_page directive
 * Use Access Control with HTTP Basic Auth using directive,   module ,   utility and   files
 * Use Digest access authentication
 * Configure https using self-signed certificates using openssl (for example: )
 * Monitoring Nginx web server

Additional Nginx documentation

 * Nginx directives: http://nginx.org/en/docs/dirindex.html. Common Nginx directives are:

Basic

 * 1) /Read Nginx release Notes/ / Changelog
 * 2) Install Nginx using docker

Advanced

 * 1) Configure Nginx as reverse proxy with Websocket support