In this tutorial, I demonstrate how to set up the LEMP stack on CentOS platforms. I target both CentOS 6 and CentOS 7 platforms, and point out differences where necessary.
Step One: Nginx
As the first step, let's install nginx on CentOS, and do basic configuration for nginx, such as enabling auto-start and customizing the firewall.Install Nginx
Let's install a pre-built stable version of nginx package from its official RPM source.On CentOS 7:
$ sudo rpm --import http://nginx.org/keys/nginx_signing.key
$ sudo rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
$ sudo yum install nginxOn CentOS 6:
$ sudo rpm --import http://nginx.org/keys/nginx_signing.key
$ sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
$ sudo yum install nginxNote that if you do not import the official nginx GPG key before installing nginx RPM, you will get this warning:
warning: /var/tmp/rpm-tmp.KttVHD: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Start Nginx
After installation, nginx does not start automatically. Let's start nginx right now, and configure it to auto-start upon boot. Also, we need to open a TCP/80 port in the firewall so that you can access nginx webserver remotely. All of these are achieved by entering the following commands.OnCentOS 7:
$ sudo service nginx start
$ sudo chkconfig nginx on
$ sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
$ sudo service iptables save
0 comments:
Post a Comment