X

Nginx Compile From Source On CentOS

Nginx (pronounced (“Engine X”) is a high performance web server. It  can be used as a web server, proxy server, load balancer, media streaming and more. It can serve static content and supports SSL. Compiling from source does not take long at all and compiling from source allows you to be in control the configuration options if they need to change later on. Also making upgrades and downgrades easier.  You can read more here

Install dependencies from yum:

yum install -y zlib zlib-devel pcre prce-devel openssl openssl-devel

the zlib packages are required for gzip, the pcre packages are required for regex, and openssl are required for SSL support.

Get the Nginx packages to install:

cd /usr/src;wget http://nginx.org/download/nginx-1.11.13.tar.gz

Un-compress the package

tar xfvz nginx-1.11.13.tar.gz

Change to the  directory:

cd nginx-1.11.13

Configure:

./configure --user=nginx --group=nginx --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --with-http_stub_status_module --with-http_ssl_module --with-pcre --with-file-aio --with-http_realip_module --without-http_scgi_module --without-http_uwsgi_module --with-http_realip_module
--with-http_gzip_static_module - Compresses responses using gzip  
--with-http_stub_status_module - Provides access to status information
--with-http_ssl_module - Allows for SSL support
--with-pcre - enables regex(Regular expressions) similar to mod_rewrite in apache
--with-file-aio - enables file AIO support
--with-http_realip_module - Changes the client address to the one sent in the specified header field. 
--without-http_scgi_module - Passes requiests to an SCGI server(not typically needed)
--without-http_uwsgi_module - Passes requests to a uwsqgi server(not typically needed)

To get more details on the configure options do

./configure --help

Install:

make && make install

The configuration files are located in /etc/nginx/ with a default sample configuration located at

/etc/nginx/nginx.conf

In the server section of the configuration, you will see where the default listen port is set

  server {
        listen       80;
        server_name  localhost;

 

This will bind the server to the default web port, if you want it to change to another port, you can update the listen line.

Start the server:

Centos 6:

Start the service:

/etc/init.d/nginx start

Ensure it starts on boot:

chkconfig --add nginx
chkconfig nginx on

Centos 7:

Start the service:

systemctl start nginx

Ensure it starts on boot:

systemctl enable nginx

This is the first part of a series on setting up and configuring nginx.

LinuxAdmin.io
0 0 votes
Article Rating
LinuxAdmin.io:
Related Post