CentrioHost Blog

Stories and News from IT Industry, Reviews & Tips | Technology Blog


How to compile and install NGINX From source on CentOS 7

Nginx is a web server which can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache.

In this tutorial we will discuss hoe to compile and install nginx in rpm based systems from source.

1. Compiling Nginx from source.

Installing dependencies using YUM:

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

Change the directory according to your wish for downloading source file:

**Here we use /usr/local/src

# cd /usr/local/src/

Download Nginx tar file:

# wget http://nginx.org/download/nginx-1.14.2.tar.gz

If you want to download latest version go toΒ http://nginx.org/en/download.html. I here used version 1.14.2

Extract tar file:

# tar xfvz nginx-1.14.2.tar.gz

Change directory:

# cd nginx-1.14.2

Add a user nginx:

 # useradd nginx

Configure:

  #  ./configure  --help   ( You will get help regarding configure such as modules to be installed ) 

–prefix= for specifing the directory which we want to install nginx. Here I used /opt/nginx/

Here I used following configuration with some necessary modules.

# ./configure --user=nginx --group=nginx --prefix=/opt/nginx --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

Install the configured:

# make
# make install

If you are using apache on the same server you need to change the port number in nginx main configuration file

 #  vi /opt/nginx/conf/nginx.conf
                  server {
                                listen       8080;
                                server_name  localhost;

save and quit.

If you enabled firewall in your server you want to add he port in firewall.

Add the service file:

# vi /usr/lib/systemd/system/nginx.service


           [Unit]
	Description=The NGINX HTTP and reverse proxy server
	After=syslog.target network.target remote-fs.target nss-lookup.target

	[Service]
	Type=forking
	PIDFile=/opt/nginx/logs/nginx.pid
	ExecStartPre=/opt/nginx/sbin/nginx -t
	ExecStart=/opt/nginx/sbin/nginx
	ExecReload=/opt/nginx/sbin/nginx -s reload
	ExecStop=/bin/kill -s QUIT $MAINPID
	PrivateTmp=true

	[Install]
	WantedBy=multi-user.target

save and quit.

Start the service:

 # systemctl start nginx
 # systemctl enable nginx

You can check version by executing following command.

# /opt/nginx/sbin/nginx  -v

Now open your browser and ensure nginx is working http://your_ip:port_number

Subscribe Now

10,000 successful online businessmen like to have our content directly delivered to their inbox. Subscribe to our newsletter!

Archive Calendar

SatSunMonTueWedThuFri
 123456
78910111213
14151617181920
21222324252627
28293031 

Over 20000 Satisfied Customers!

  • web hosting reviewer
    Valerie Quinn
    CTO, Acteon Group

    Centriohost staff were fantastic, I had a concern with a domain and they got back to me very quickly and they helped me to resolve the issue! ~ . . . Read more

  • Joomla hosting reviewer
    Collin Bryan
    Photographer, Allister Freeman

    I'm using centrio for my portfolio since 2006. The transition was seamless, the support was immediate, and everything works perfectly. ~ . . . Read more

  • dedicated server reviewer
    Harry Collett
    Actor, A&J Artists

    Very easy to understand & use even though I am not very technologically minded. No complications whatsoever & I wouldn't hesitate to recommend it to all. ~ . . . Read more

  • vps web hosting reviewer
    Porfirio Santos
    Technician, Diageo PLC

    Centrio support team have been amazingly responsive and helpful to any of my queries, thank you so much to the Centriohost have been amazingly responsive and helpful to any of my queries πŸ‘πŸ‘πŸ‘ ~ . . . Read more

  • wordpress hosting plans reviewer
    Catherine Auer
    Doctor, SmartClinics

    Anytime I've had a problem I can't solve, I've found Centriohost to be diligent and persistent. They simply won't let an issue go until the client is happy. ~ . . . Read more

  • reseller hosting reviewer
    Effectivo Social
    Freelancer, Fiverr

    Recommend their shared hosting for all my SME web design clients. Their cloud or VME offerings are too great to deal with. Pricing is perfect and suitable for all users (Ν β‰– ΝœΚ–Ν β‰–) πŸ‘Œ ~ . . . Read more

Top