[Operation and maintenance engineer learning four sequels] Linux configuration and installation of Nginx for Web services

0. Check whether wget is installed

wget --version

insert image description here

1. Install wget

yum install -y wget
wget -c https://nginx.org/download/nginx-1.24.0.tar.gz

insert image description here

insert image description here

2. Download the Nginx installation package

insert image description here

  • Then find a version, move the mouse to it, right click - copy the link address (stable version is recommended)

insert image description here

wget download nginx installation package

Use the wget command to download the Nginx installation package to /usr/local/the directory

wget -c https://nginx.org/download/nginx-1.24.0.tar.gz

3. Unzip the nginx tar package

tar -zxvf nginx-1.24.0.tar.gz

insert image description here

4. Install related dependent files

yum install -y gcc-c++ zlib zlib-devel openssl-devel pcre pcre-devel

insert image description here

explain

This command is used to install some development tools and dependent libraries on the Linux system based on the yum package management tool. The specific meaning is as follows:

  • yum: is a package management tool commonly used on Linux distributions such as Red Hat, CentOS, and Fedora.
  • install: This command parameter is used to install the package.
  • -y: This option means to install directly without prompting before confirming the installation.
  • gcc-c++: is the package for the C++ compiler.
  • zlib zlib-devel: is a library for data compression and decompression and its development kit.
  • openssl openssl-devel: is an open source software library for providing secure communications over the web.
  • pcre pcre-devel: is a library for working with regular expressions and its development kit.

The purpose of this command is to install the C++ compiler, zlib compression library and development tools, openssl secure communication library and development tools, and libraries and development tools for processing regular expressions.

5. Switch to the nginx directory

  • lsGo to the directory of the Nginx version you downloaded

insert image description here

6. Configure the current nginx

./configure

insert image description here

7. Compile and install nginx

make && make install

Use the make && make install command to compile and install

insert image description here

Note:
./configure(配置)、make(编译)、make install(安装)These three commands can be used &&to connect the commands to execute, which means that the following commands will be executed after the current command is completed normally. This method is very good, which not only saves time, but also prevents errors. For example:

./configure && make && make install

8. Switch to the sbin directory of nginx

cd /usr/local/nginx/sbin

insert image description here

9. Check the version of nginx

./nginx -v

insert image description here

10. View the firewall of the Linux system

Accessing nginx in linux in the windows system is inaccessible by default because of firewall issues.
The firewall of the Linux system is enabled by default, you can turn off or disable the firewall (not recommended)

systemctl status firewalld

For port opening of Linux firewall, please refer to section 6-8 of my article:
https://blog.csdn.net/weixin_43576565/article/details/131453867

For common commands of Linux firewall, please refer to section 14-15 of my article :
https://blog.csdn.net/weixin_43576565/article/details/131376844

11. Open access port number

By default, the Linux firewall will block the port number we visit, so we need to release the port number we want to visit.

# nginx的访问端口号是80(http协议的默认端口号就是80),所以这里,我们需要去放行80端口号
# 这里我们需要添加80端口号
firewall-cmd --permanent --add-port=80/tcp

After the release, restart the Linux firewall.

# 修改配置后需要重启防火墙
firewall-cmd --reload

After we have added the port number 80, we can check whether the port number 80 has been added successfully.

# 查看80端口号
firewall-cmd --query-port=80/tcp

Common commands of firewall-cmd:

# 查看防火墙状态
firewall-cmd --state

# 重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload

# 查看开放的端口
firewall-cmd --list-ports

# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
# 开启防火墙端口
firewall-cmd --zone=public --add-port=80/tcp --permanent

# 移除端口号
firewall-cmd --permanent --remove-port=80/tcp
# 关闭端口命令
firewall-cmd --zone=public --remove-port=80/tcp --permanent

# 查询端口是否开放
firewall-cmd --query-port=80/tcp
# 查看端口是否打开
firewall-cmd --zone=public --query-port=80/tcp

12. Start the nginx service

# 开启nginx服务
./nginx
# 关闭nginx服务
./nginx -s stop
# 重启nginx服务
./nginx -s reload

insert image description here

  • After the nginx service is started, there is no prompt for successful startup, and the network IP of the Linux system needs to be used to access it.
    If you can see this page when visiting the browser, then the nginx service has started successfully.

insert image description here

  • You can also judge whether to start by checking whether the process exists worker, andmaster

insert image description here

13. Modify configuration

(1) Modify the port number, domain name and default access page

vi /usr/local/nginx/conf/nginx.conf

insert image description here

(2) Modify page content

cd /usr/local/nginx/html/

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43576565/article/details/131666443