Table of Contents
✅ 2. Install EPEL Repository (if not already installed)
✅ 3. Install Nginx
✅ 4. Start and Enable Nginx
✅ 5. Configure Firewall (if using firewalld)
Home Operation and Maintenance CentOS How to install Nginx on CentOS

How to install Nginx on CentOS

Jul 24, 2025 am 02:01 AM
centos nginx

Update the system: Run sudo yum update -y to ensure the system is up to date; 2. Install EPEL source: execute sudo yum install epel-release -y to obtain the Nginx package; 3. Install Nginx: Use sudo yum install nginx -y to install the service; 4. Start and enable Nginx: Set up the power-on startup through sudo systemctl start nginx and sudo systemctl enable nginx, and use sudo systemctl status nginx to confirm the running status; 5. Configure the firewall: If firewalld is enabled, run sudo firewall-cmd --permanent --add-service=http and https overload the rules; 6. Optional security configuration: Edit the files under /etc/nginx/nginx.conf or conf.d to adjust permissions, disable server tokens, or use Certbot to configure SSL certificates; after completion, you can see the Nginx welcome page, the installation is successful and there is no need to compile from the source code.

How to install Nginx on CentOS

Installing Nginx on CentOS is straightforward and only takes a few steps. Here's how to do it properly on CentOS 7 or 8 (also works on Stream versions):

How to install Nginx on CentOS

✅ 1. Update Your System

Always start with a system update:

 sudo yum update -y

✅ 2. Install EPEL Repository (if not already installed)

Nginx is available in the EPEL (Extra Packages for Enterprise Linux) repo:

How to install Nginx on CentOS
 sudo yum install epel-release -y

Why? EPEL gives you access to extra packages not in the base CentOS repos — including Nginx.


✅ 3. Install Nginx

Now install Nginx:

How to install Nginx on CentOS
 sudo yum install nginx -y

✅ 4. Start and Enable Nginx

Start the service and set it to launch at boot:

 sudo systemctl start nginx
sudo systemctl enable nginx

Check status to confirm it's running:

 sudo systemctl status nginx

You should see active (running) .


✅ 5. Configure Firewall (if using firewalld)

If you have firewalld enabled (default on CentOS), allow HTTP and HTTPS:

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

? Test in browser:
Visit your server's IP address ( http://your-server-ip ) — you should see the Nginx welcome page.


✅ 6. (Optional) Secure Nginx

  • Edit config: /etc/nginx/nginx.conf or site-specific files in /etc/nginx/conf.d/
  • Set up SSL with Let's Encrypt using Certbot if needed
  • Adjust permissions and disable server tokens if in production

That's it!
Nginx is now installed, running, and ready to serve content.
No need to compile from source unless you need custom modules — the EPEL package is stable and well-maintained.

The above is the detailed content of How to install Nginx on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to limit user resources in Linux? How to configure ulimit? How to limit user resources in Linux? How to configure ulimit? May 29, 2025 pm 11:09 PM

Linux system restricts user resources through the ulimit command to prevent excessive use of resources. 1.ulimit is a built-in shell command that can limit the number of file descriptors (-n), memory size (-v), thread count (-u), etc., which are divided into soft limit (current effective value) and hard limit (maximum upper limit). 2. Use the ulimit command directly for temporary modification, such as ulimit-n2048, but it is only valid for the current session. 3. For permanent effect, you need to modify /etc/security/limits.conf and PAM configuration files, and add sessionrequiredpam_limits.so. 4. The systemd service needs to set Lim in the unit file

What are the Debian Nginx configuration skills? What are the Debian Nginx configuration skills? May 29, 2025 pm 11:06 PM

When configuring Nginx on Debian system, the following are some practical tips: The basic structure of the configuration file global settings: Define behavioral parameters that affect the entire Nginx service, such as the number of worker threads and the permissions of running users. Event handling part: Deciding how Nginx deals with network connections is a key configuration for improving performance. HTTP service part: contains a large number of settings related to HTTP service, and can embed multiple servers and location blocks. Core configuration options worker_connections: Define the maximum number of connections that each worker thread can handle, usually set to 1024. multi_accept: Activate the multi-connection reception mode and enhance the ability of concurrent processing. s

What are the SEO optimization techniques for Debian Apache2? What are the SEO optimization techniques for Debian Apache2? May 28, 2025 pm 05:03 PM

DebianApache2's SEO optimization skills cover multiple levels. Here are some key methods: Keyword research: Use tools (such as keyword magic tools) to mine the core and auxiliary keywords of the page. High-quality content creation: produce valuable and original content, and the content needs to be conducted in-depth research to ensure smooth language and clear format. Content layout and structure optimization: Use titles and subtitles to guide reading. Write concise and clear paragraphs and sentences. Use the list to display key information. Combining multimedia such as pictures and videos to enhance expression. The blank design improves the readability of text. Technical level SEO improvement: robots.txt file: Specifies the access rights of search engine crawlers. Accelerate web page loading: optimized with the help of caching mechanism and Apache configuration

How to implement automated deployment of Docker on Debian How to implement automated deployment of Docker on Debian May 28, 2025 pm 04:33 PM

Implementing Docker's automated deployment on Debian system can be done in a variety of ways. Here are the detailed steps guide: 1. Install Docker First, make sure your Debian system remains up to date: sudoaptupdatesudoaptupgrade-y Next, install the necessary software packages to support APT access to the repository via HTTPS: sudoaptinstallapt-transport-httpsca-certificatecurlsoftware-properties-common-y Import the official GPG key of Docker: curl-

How to install PHP and common extensions on CentOS? How to install PHP and common extensions on CentOS? Jun 11, 2025 pm 04:14 PM

ToinstallPHPandcommonextensionsonCentOS,firstenableEPELandRemirepositoriesviasudoyuminstallepel-release-yandsudoyuminstallhttps://rpms.remirepo.net/enterprise/remi-release-7.rpm-y,theninstallyum-utils.Next,enablethedesiredPHPstreamsuchassudoyum-confi

How to compile Nginx from source with a custom module? How to compile Nginx from source with a custom module? Jun 11, 2025 pm 04:01 PM

How to compile Nginx with custom modules from source? First, prepare the required dependencies and tools, and then add the module path through the --add-module parameter in the configuration stage, and finally compile and install. The specific steps are as follows: 1. Install necessary dependencies such as GCC, PCRE, zlib, OpenSSL and make; 2. Download and decompress the Nginx source code; 3. Use the --add-module parameter to specify the module path when executing the ./configure command, and enable other modules or options as needed; 4. Run make and sudomakeinstall to complete the compilation and installation; 5. Use the nginx-V command to verify whether the module is successfully added; 6. Modify ngin

What is the command to start, stop, or restart Nginx? What is the command to start, stop, or restart Nginx? Jun 18, 2025 am 12:05 AM

To start, stop or restart Nginx, the specific commands depend on the system type and installation method. 1. For modern systems that use systemd (such as Ubuntu16.04, Debian8, CentOS7), you can use: sudosystemctlstartnginx, sudosystemctlstopnginx, sudosystemctlrestartnginx, and use sudosystemctlreloadnginx after configuration changes; 2. For old systems that use SysVinit, use the service command: sudoservicenginxstart,

CentOS server has no network connection, how to fix it? CentOS server has no network connection, how to fix it? Jun 19, 2025 am 12:13 AM

When the CentOS server cannot be connected to the network, you can follow the following steps to check: 1. Check the status of the network interface, use iplinkshow to confirm whether the interface is enabled, if not enabled, use sudoiplinksetup to start, and use ipaddrshow to check the IP allocation status; 2. If it is in DHCP mode, run sudodhclient to obtain the IP. If it is static configuration, check the IP, gateway and DNS settings in /etc/sysconfig/network-scripts/ifcfg- and restart the network service; 3. Check the routing table iprouteshow to ensure that there is a default gateway. If there is no, add it temporarily or modify GATEWAY in the configuration file.

See all articles