Linux installation nginx - complete example

The following is an example of a simple shell script to install Nginx on CentOS:

#!/bin/bash

# 安装库
yum install epel-release -y
# 安装 Nginx
yum install nginx -y

# 启动 Nginx 服务
systemctl start nginx

# 关闭防火墙
systemctl stop firewalld

# 禁用防火墙
systemctl disable firewalld

# 设置 Nginx 开机自启动
sudo systemctl enable nginx

Save the above code in a installNginx.shfile called and make sure the file has execute permission.

Then, run the following command in a terminal to execute the script:

If the permissions are not enough, change the permissions.

chmod +x install_nginx.sh
./install_nginx.sh

The script will first install the EPEL repository and then yuminstall Nginx using the command. Next, start the Nginx service and set it to start automatically at boot.

It takes a long time to download, don't worry.

Note that a user with sudo privileges is required to execute the script. Before running the script, make sure you are logged in as the sudo user or have sudo privileges.

This script is just a basic example and may need to be adjusted for your specific environment and needs. You can perform additional configurations and modifications as needed, such as modifying Nginx configuration files, etc. Please read the documentation carefully and understand the changes before using the script.

Modify the Nginx port number

vi /etc/nginx/nginx.conf

Access the IP after Nginx starts

You can see that we have successfully accessed. The reason for welcome to centos is that nginx was started before nginx was not configured, but it is sure that nginx must have started.

Check whether nginx starts successfully.

EPEL overview

EPEL (Extra Packages for Enterprise Linux) is a community-driven project that provides additional software packages for distributions based on Red Hat Enterprise Linux (RHEL) and its derivatives such as CentOS and Oracle Linux. It extends the official software repository, enabling users to easily install and manage various open source software and tools.

The goal of the EPEL project is to provide a wide selection of software packages for enterprise-level Linux distributions, including but not limited to web servers, databases, development tools, graphical interface applications, etc. These packages are maintained by the community and have been reviewed and tested by the EPEL project team to ensure their compatibility and stability with RHEL and its derivative distributions.

By using the EPEL software repository, users can easily install and update various commonly used software packages without manual compilation and installation. The EPEL project provides an additional software source configuration file that enables users to obtain packages from EPEL repositories using package management tools such as yum and dnf.

To use the EPEL repository, after installing an appropriate distribution such as CentOS, simply execute the following command to add the EPEL repository to your system:

yum install epel-release

After adding the EPEL repository, you can use the yum or dnf command to install the packages in EPEL, for example:

yum install nginx
dnf install git

This will install Nginx and Git packages from the EPEL repository.

To summarize, EPEL is a project to provide additional packages for RHEL and its derivative distributions, which extends the official repositories and makes it easier for users to obtain and manage various open source software and tools.

Guess you like

Origin blog.csdn.net/feng8403000/article/details/131617146