• Home
  • Servers
  • Hosting Tutorials
    • cPanel&WHM
  • WordPress Tutorial
    • WordPress General
    • WooCommerce
    • Useful Plugin

Subscribe to Updates

Get the latest creative news from FooBar about art, design and business.

What's Hot

Important WP 6.2 Issue — Read Before Updating

April 5, 2023

WordPress Two-Factor Authentication (2FA): what is it & using it on your site

January 26, 2023

The biggest source of WordPress vulnerabilities

January 26, 2023
Facebook Twitter Instagram
  • Home
  • Servers
    Featured
    Servers

    What Is Imunify360? How Does It Enhance Website Security?

    By The GeekJanuary 2, 20230
    Recent

    What Is Imunify360? How Does It Enhance Website Security?

    January 2, 2023

    How to set up a Raspberry Pi ownCloud server in 7 steps

    December 20, 2022

    How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7

    December 20, 2022
  • Hosting Tutorials
    1. cPanel&WHM
    Featured
    Hosting Tutorials

    What is Let’s Encrypt SSL certificate

    By The GeekDecember 26, 20220
    Recent

    What is Let’s Encrypt SSL certificate

    December 26, 2022

    What Is Web Hosting? What Is Shared Hosting?

    December 26, 2022

    How to install cPanel on CentOS 7

    December 22, 2022
  • WordPress Tutorial
    1. WordPress General
    2. WooCommerce
    3. Useful Plugin
    Featured
    General

    Important WP 6.2 Issue — Read Before Updating

    By The GeekApril 5, 20230
    Recent

    Important WP 6.2 Issue — Read Before Updating

    April 5, 2023

    WordPress Two-Factor Authentication (2FA): what is it & using it on your site

    January 26, 2023

    The biggest source of WordPress vulnerabilities

    January 26, 2023
Facebook Instagram
Horizen.ro – Tech Blog & Server environmentHorizen.ro – Tech Blog & Server environment
Subscribe
  • Home
  • Servers
    Featured
    Servers

    What Is Imunify360? How Does It Enhance Website Security?

    By The GeekJanuary 2, 20230
    Recent

    What Is Imunify360? How Does It Enhance Website Security?

    January 2, 2023

    How to set up a Raspberry Pi ownCloud server in 7 steps

    December 20, 2022

    How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7

    December 20, 2022
  • Hosting Tutorials
    1. cPanel&WHM
    Featured
    Hosting Tutorials

    What is Let’s Encrypt SSL certificate

    By The GeekDecember 26, 20220
    Recent

    What is Let’s Encrypt SSL certificate

    December 26, 2022

    What Is Web Hosting? What Is Shared Hosting?

    December 26, 2022

    How to install cPanel on CentOS 7

    December 22, 2022
  • WordPress Tutorial
    1. WordPress General
    2. WooCommerce
    3. Useful Plugin
    Featured
    General

    Important WP 6.2 Issue — Read Before Updating

    By The GeekApril 5, 20230
    Recent

    Important WP 6.2 Issue — Read Before Updating

    April 5, 2023

    WordPress Two-Factor Authentication (2FA): what is it & using it on your site

    January 26, 2023

    The biggest source of WordPress vulnerabilities

    January 26, 2023
Horizen.ro – Tech Blog & Server environmentHorizen.ro – Tech Blog & Server environment
Home»Servers»How to Install and Configure Nginx on CentOS 7
Servers

How to Install and Configure Nginx on CentOS 7

The GeekBy The GeekDecember 20, 2022Updated:January 6, 2023No Comments4 Mins Read
Facebook Twitter Pinterest LinkedIn Tumblr Email
Share
Facebook Twitter LinkedIn Pinterest Email
  • Nginx on your CentOS 7 server, what it is, and how to install it.
  • Default Server Root
  • Server Block Configuration
  • Nginx Global Configuration

Nginx on your CentOS 7 server, what it is, and how to install it.

This tutorial will teach you how to install and start . Nginx is a popular high-performance web server.

Prerequisites

The steps in this tutorial require a non-root user with sudo privileges. See our Initial Server Setup with CentOS 7 tutorial to learn how to set up this user.

Step 1 — Adding the EPEL Software Repository

To add the CentOS 7 EPEL repository, first connect to your CentOS 7 machine via SSH, then use the yum command to install the extended package repository:

sudo yum install epel-release

You’ll be prompted to verify that you want to install the software. Type y then ENTER to continue.

Next, you’ll install the actual nginx software package.

Step 2 — Installing Nginx

Now that the EPEL repository is installed on your server, install Nginx using the following yum command:

sudo yum install nginx

Again, answer yes to the verification prompt, then Nginx will finish installing.

Step 3 — Starting Nginx

Nginx will not start automatically after it is installed. To get Nginx running, use the systemctl command:

sudo systemctl start nginx

You can check the status of the service with systemctl status:

sudo systemctl status nginx

Output● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2022-01-24 20:14:24 UTC; 5s ago
  Process: 1898 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 1896 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 1895 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 1900 (nginx)
   CGroup: /system.slice/nginx.service
           ├─1900 nginx: master process /usr/sbin/nginx
           └─1901 nginx: worker process

Jan 24 20:14:24 centos-updates systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 24 20:14:24 centos-updates nginx[1896]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 24 20:14:24 centos-updates nginx[1896]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 24 20:14:24 centos-updates systemd[1]: Started The nginx HTTP and reverse proxy server.

The service should be active.

If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser:

http://server_domain_name_or_IP/

You will see the default CentOS 7 Nginx web page, which is there for informational and testing purposes. It should look something like this:

CentOS 7 Nginx Default

If you see this page, then your web server is now correctly installed.

Note: To find your server’s public IP address, find the network interfaces on your machine by typing:

ip addr

Output1. lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN

. . .
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

. . .

You may see a number of interfaces here depending on the hardware available on your server. The lo interface is the local loopback interface, which is not the one we want. In our example above, the eth0 interface is what we want.

Once you have the interface name, you can run the following command to reveal your server’s public IP address. Substitute the interface name you found above:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Before continuing, you will probably want to enable Nginx to start when your system boots. To do so, enter the following command:

sudo systemctl enable nginx

Nginx is now installed and running.

Step 4 — Exploring and Configuring Nginx

If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.

Default Server Root

The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /etc/nginx/conf.d/default.conf.

Server Block Configuration

Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in /etc/nginx/conf.d. Files that end with .conf in that directory will be loaded when Nginx is started.

Nginx Global Configuration

The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.

Conclusion

Once you have Nginx installed on your CentOS 7 server, you can go on to install the full LEMP Stack on CentOS 7. Next, you can configure cPanel to start your web server more easily.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
The Geek
  • Website

Related Posts

What Is Imunify360? How Does It Enhance Website Security?

January 2, 2023

How to set up a Raspberry Pi ownCloud server in 7 steps

December 20, 2022

How To Install Linux, Nginx, MySQL, PHP (LEMP) stack On CentOS 7

December 20, 2022
Add A Comment

Leave A Reply Cancel Reply

Editors Picks

Important WP 6.2 Issue — Read Before Updating

April 5, 2023

WordPress Two-Factor Authentication (2FA): what is it & using it on your site

January 26, 2023

The biggest source of WordPress vulnerabilities

January 26, 2023

15 ways to secure your WordPress site

January 19, 2023
Top Reviews
Advertisement
Demo
Horizen.ro – Tech Blog & Server environment
Facebook Twitter Instagram Pinterest Vimeo YouTube
  • Home
  • Hosting Tutorials
  • Cpanel & WHM
  • Cookie Policy (EU)
© 2023

Type above and press Enter to search. Press Esc to cancel.

Manage Cookie Consent
We use technologies like cookies to store and/or access device information. We do this to improve browsing experience and to show personalized ads. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.
Functional Always active
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes. The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.
Manage options Manage services Manage vendors Read more about these purposes
View preferences
{title} {title} {title}