NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.
If you are coming from Apache, the "sites-available" and "sites-enabled" directories will be familiar.
These directories are used to define configurations for your websites. Files are generally created in the "sites-available" directory, and then symbolically linked to the "sites-enabled" directory when they are ready to go live.
The "conf.d" directory can be used for site configuration as well. Every file within this directory ending with ".conf" is read into the configuration when Nginx is started, so make sure every file defines valid Nginx configuration syntax.
Most of the other files within the "/etc/nginx" directory contain configuration details of specific processes or optional components.
However, the "nginx.conf" file is the main configuration file. We will explore this file in more depth.
========================
vim /etc/nginx/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
=========================
the server decides what user to run as by the "user www-data" line. This is the typical web server user for Ubuntu.
The "pid" directive specifies where the process pid will be stored for internal reference. The "worker_processes" defines how many concurrent processes that Nginx will use.
Steps to Install Nginx from Source in CentOS 7:-
Installing Nginx from Source:-
1. Download and install Nginx Dependencies: -
A) PCRE library – required by NGINX Core and Rewrite modules and provides support for regular expressions:
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar -zxf pcre-8.39.tar.gz
cd pcre-8.39
./configure
make
make install
If suppose you get below error while installing PCRE library, You might need to install gcc-c++ autoconf automake
Error: You need a C++ compiler for C++ support
Sol:- yum install gcc gcc-c++ autoconf automake
B) zlib library – required by NGINX Gzip module for headers compression:
wget http://zlib.net/zlib-1.2.8.tar.gz
tar -zxf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
Make && make install
C) OpenSSL library – required by NGINX SSL modules to support the HTTPS protocol:
yum -y install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel
2. Download nginx and install:-
wget http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxf nginx-1.10.2.tar.gz
cd nginx-1.10.2
ls
3. Configure Nginx in User Defined Paths:-
./configure --user=nginx --group=nginx --prefix=/etc/web/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/web/nginx/nginx.conf --error-log-path=/var/log/web/nginx/error/error.log --http-log-path=/var/log/web/nginx/access/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock
You can customize the nginx path. To know more click below link.
For your references: https://www.nginx.com/resources/wiki/start/topics/tutorials/installoptions/
make
make install
nginx -v
4. Start the nginx service::-
systemctl start nginx.service
systemctl enable nginx.service
systemctl status nginx.service
If you get below error while starting nginx services. You have to add a entry in below file
vim /lib/systemd/system/nginx.service
Error:-
Failed to start nginx.service: Unit nginx.service failed to load: No such file or directory.
Sol:
Obviously installation from source did not provide a unit file. You need to create a unit file for nginx like this.
========================================================
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
========================================================
then you have to reload the daemon
systemctl daemon-reload
ConversionConversion EmoticonEmoticon