I. Introduction.
This tutorial will teaches you how to install Nginx on Linux – CentOS 7 server and configure a static web site. Nginx is [engine x], it is free and open source high-performance web server. It also acts as a reverse proxy server
II. Prerequisites.
1. Login to your system via SSH. You can use PuTTy tool or Poderosa tool,…
2. Login with root user. If you are logged in as another user, you will need to add sudo before each command.
III. Install PHP on CentOS 7 by step by step.
To install MySQL 8.0 on Linux – CentOS 7. Follow these steps:
Step 1. Turn on EPEL repository.
Step 2. Install Nginx.
Step 3. Allow HTTP and HTTPS traffic.
Step 4. Start Nginx.
Step 5. Testing the Installation.
You can see details of Video on How to install Nginx on Linux – CentOS 7 as below.
[Sorry, the video we will update later]
Or you can see the details and follow the steps below.
Step 1. Turn on EPEL repository.
Enter command below:
sudo yum install epel-release
Step 2. Install Nginx.
Enter command below:
※ Note: You answer Yes to prompt.
sudo yum install nginx
Sample Output:
[root@devopsio ~]# sudo yum install nginx
Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.12.2-3.el7 will be installed
--> Processing Dependency: nginx-all-modules = 1:1.12.2-3.el7 for package: 1:nginx-1.12.2-3.el7.x86_64
--> Running transaction check
---> Package nginx-all-modules.noarch 1:1.12.2-3.el7 will be installed
--> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch
--> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch
--> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch
--> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch
--> Processing Dependency: nginx-mod-mail = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch
--> Processing Dependency: nginx-mod-stream = 1:1.12.2-3.el7 for package: 1:nginx-all-modules-1.12.2-3.el7.noarch
--> Running transaction check
---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-3.el7 will be installed
---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-3.el7 will be installed
---> Package nginx-mod-http-perl.x86_64 1:1.12.2-3.el7 will be installed
---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-3.el7 will be installed
---> Package nginx-mod-mail.x86_64 1:1.12.2-3.el7 will be installed
---> Package nginx-mod-stream.x86_64 1:1.12.2-3.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===============================================================================================
Package Arch Version Repository Size
===============================================================================================
Installing:
nginx x86_64 1:1.12.2-3.el7 epel 531 k
Installing for dependencies:
nginx-all-modules noarch 1:1.12.2-3.el7 epel 16 k
nginx-mod-http-geoip x86_64 1:1.12.2-3.el7 epel 23 k
nginx-mod-http-image-filter x86_64 1:1.12.2-3.el7 epel 27 k
nginx-mod-http-perl x86_64 1:1.12.2-3.el7 epel 36 k
nginx-mod-http-xslt-filter x86_64 1:1.12.2-3.el7 epel 26 k
nginx-mod-mail x86_64 1:1.12.2-3.el7 epel 54 k
nginx-mod-stream x86_64 1:1.12.2-3.el7 epel 76 k
Transaction Summary
===============================================================================================
Install 1 Package (+7 Dependent packages)
Total download size: 790 k
Installed size: 1.9 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): nginx-all-modules-1.12.2-3.el7.noarch.rpm | 16 kB 00:00:00
(2/8): nginx-1.12.2-3.el7.x86_64.rpm | 531 kB 00:00:00
(3/8): nginx-mod-http-geoip-1.12.2-3.el7.x86_64.rpm | 23 kB 00:00:00
(4/8): nginx-mod-http-image-filter-1.12.2-3.el7.x86_64.rpm | 27 kB 00:00:00
(5/8): nginx-mod-http-perl-1.12.2-3.el7.x86_64.rpm | 36 kB 00:00:00
(6/8): nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64.rpm | 26 kB 00:00:00
(7/8): nginx-mod-mail-1.12.2-3.el7.x86_64.rpm | 54 kB 00:00:00
(8/8): nginx-mod-stream-1.12.2-3.el7.x86_64.rpm | 76 kB 00:00:00
-----------------------------------------------------------------------------------------------
Total 821 kB/s | 790 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64 1/8
Installing : 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64 2/8
Installing : 1:nginx-mod-http-image-filter-1.12.2-3.el7.x86_64 3/8
Installing : 1:nginx-mod-mail-1.12.2-3.el7.x86_64 4/8
Installing : 1:nginx-mod-stream-1.12.2-3.el7.x86_64 5/8
Installing : 1:nginx-mod-http-geoip-1.12.2-3.el7.x86_64 6/8
Installing : 1:nginx-all-modules-1.12.2-3.el7.noarch 7/8
Installing : 1:nginx-1.12.2-3.el7.x86_64 8/8
Verifying : 1:nginx-all-modules-1.12.2-3.el7.noarch 1/8
Verifying : 1:nginx-mod-http-xslt-filter-1.12.2-3.el7.x86_64 2/8
Verifying : 1:nginx-mod-http-perl-1.12.2-3.el7.x86_64 3/8
Verifying : 1:nginx-mod-http-image-filter-1.12.2-3.el7.x86_64 4/8
Verifying : 1:nginx-1.12.2-3.el7.x86_64 5/8
Verifying : 1:nginx-mod-mail-1.12.2-3.el7.x86_64 6/8
Verifying : 1:nginx-mod-stream-1.12.2-3.el7.x86_64 7/8
Verifying : 1:nginx-mod-http-geoip-1.12.2-3.el7.x86_64 8/8
Installed:
nginx.x86_64 1:1.12.2-3.el7
Dependency Installed:
nginx-all-modules.noarch 1:1.12.2-3.el7 nginx-mod-http-geoip.x86_64 1:1.12.2-3.el7
nginx-mod-http-image-filter.x86_64 1:1.12.2-3.el7 nginx-mod-http-perl.x86_64 1:1.12.2-3.el7
nginx-mod-http-xslt-filter.x86_64 1:1.12.2-3.el7 nginx-mod-mail.x86_64 1:1.12.2-3.el7
nginx-mod-stream.x86_64 1:1.12.2-3.el7
Complete!
Step 3. Allow HTTP and HTTPS traffic.
Enter command below:
sudo firewall-cmd –permanent –zone=public –add-service=http
sudo firewall-cmd –permanent –zone=public –add-service=https
sudo firewall-cmd –reload
HTTP uses port 80, HTTP uses port 443. To verify that port 80 or 443 opened, enter command below:
sudo ss -tulpn
Step 4. Start Nginx.
Enter command below:
sudo systemctl start nginx
Enable command is allow Nginx to start when your system boots. Enter command below:
sudo systemctl enable nginx
Sample Output:
[root@devopsio ~]# sudo systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
Step 5. Testing the Installation.
1. Check Nginx version. Enter command below:
nginx -v
Sample Output:
[root@devopsio ~]# nginx -v
nginx version: nginx/1.12.2
2. Or you can check by method. On Web Browser, input URL below:
http://server_domain_name_or_IP/
Output:
If have can see this page, then your web server is correctly installed.
If you do not know your server IP address run the following ip command:
ip a
Sample Output:
[root@devopsio ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether f2:3c:91:58:75:a5 brd ff:ff:ff:ff:ff:ff
inet 45.56.114.126/24 brd 45.56.114.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 2600:3c02::f03c:91ff:fe58:75a5/64 scope global noprefixroute dynamic
valid_lft 2591997sec preferred_lft 604797sec
inet6 fe80::f03c:91ff:fe58:75a5/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3. Or you can also use the curl command to get same info using the cli:
curl -I http://45.56.114.126
curl http://45.56.114.126
Sample Output:
[root@devopsio ~]# curl -I http://45.56.114.126
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sun, 04 Aug 2019 23:04:49 GMT
Content-Type: text/html
Content-Length: 3700
Last-Modified: Fri, 10 May 2019 08:08:40 GMT
Connection: keep-alive
ETag: "5cd53188-e74"
Accept-Ranges: bytes
[root@devopsio ~]# curl http://45.56.114.126
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Test Page for the Nginx HTTP Server on Fedora</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
/*<![CDATA[*/
body {
background-color: #fff;
color: #000;
font-size: 0.9em;
font-family: sans-serif,helvetica;
margin: 0;
padding: 0;
}
:link {
color: #c00;
}
:visited {
color: #c00;
}
a:hover {
color: #f50;
}
h1 {
text-align: center;
margin: 0;
padding: 0.6em 2em 0.4em;
background-color: #294172;
color: #fff;
font-weight: normal;
font-size: 1.75em;
border-bottom: 2px solid #000;
}
h1 strong {
font-weight: bold;
font-size: 1.5em;
}
h2 {
text-align: center;
background-color: #3C6EB4;
font-size: 1.1em;
font-weight: bold;
color: #fff;
margin: 0;
padding: 0.5em;
border-bottom: 2px solid #294172;
}
hr {
display: none;
}
.content {
padding: 1em 5em;
}
.alert {
border: 2px solid #000;
}
img {
border: 2px solid #fff;
padding: 2px;
margin: 2px;
}
a:hover img {
border: 2px solid #294172;
}
.logos {
margin: 1em;
text-align: center;
}
/*]]>*/
</style>
</head>
<body>
<h1>Welcome to <strong>nginx</strong> on Fedora!</h1>
<div class="content">
<p>This page is used to test the proper operation of the
<strong>nginx</strong> HTTP server after it has been
installed. If you can read this page, it means that the
web server installed at this site is working
properly.</p>
<div class="alert">
<h2>Website Administrator</h2>
<div class="content">
<p>This is the default <tt>index.html</tt> page that
is distributed with <strong>nginx</strong> on
Fedora. It is located in
<tt>/usr/share/nginx/html</tt>.</p>
<p>You should now put your content in a location of
your choice and edit the <tt>root</tt> configuration
directive in the <strong>nginx</strong>
configuration file
<tt>/etc/nginx/nginx.conf</tt>.</p>
</div>
</div>
<div class="logos">
<a href="http://nginx.net/"><img
src="nginx-logo.png"
alt="[ Powered by nginx ]"
width="121" height="32" /></a>
<a href="http://fedoraproject.org/"><img
src="poweredby.png"
alt="[ Powered by Fedora ]"
width="88" height="31" /></a>
</div>
</div>
</body>
</html>
IV. Conclusion.
In this tutorial, we was install Nginx on CentOS 7 server. In next part of the series I will show you how to displays a basic website use Nginx running Nginx server.
Install Nginx Linux – CentOS 7 is complete. Wish you success and luck.
Thanks and best regards!
— Pring —
1 comment
Worked for me