[Nginx Basics] Linux virtual machine installation nginx

Table of contents

1. Version difference

2. Compile and install

3. Start nginx

About the firewall

4. Install as a system service


1. Version difference

Commonly used versions are divided into four camps
  • Nginx open source version http://nginx.org/
  • Nginx plus commercial version https://www.nginx.com
  • openresty http://openresty.org/cn/
  • Tengine http://tengine.taobao.org/

2. Compile and install

nginx installation package:

Link: https://pan.baidu.com/s/1iGk_UROCNaiaXFsxndmQoA?pwd=xsqm 

The version 1-21.6 is installed here, and the tar.gz compressed package is transferred to the virtual machine and decompressed
tar -zxvf nginx-1.21.6.tar.gz
After installing gcc and related dependencies
yum install - y gcc
yum install - y pcre pcre - devel # install perl library
yum install - y zlib zlib - devel  # Install the zlib library
official installation
// After entering the nginx-1.21.6 directory, you can see the configure configuration file and install it through it
./configure -- prefix=/usr/local/nginx
make
make install

3. Start nginx

Enter the installed directory /usr/local/nginx/sbin
./nginx start
./nginx -s stop quick stop
./nginx -s quit graceful shutdown, complete the accepted connection request before exiting
./nginx -s reload reload configuration

After startup, you can access nginx through the ip address, and you can see that the default access page appears, and nginx is installed successfully.

About the firewall

The access timeout may be because the firewall is not closed

turn off firewall
systemctl stop firewalld.service
Disable the firewall from booting
systemctl disable firewalld.service release port
firewall - cmd -- zone=public -- add - port=80/tcp -- permanent
restart firewall
firewall - cmd -- reload

4. Install as a system service

It is too troublesome to start nginx under /usr/local/nginx/sbin every time. How to implement systemctl start nginx.service to start nginx

Create service script
vi /usr/lib/systemd/system/nginx.service

Service script content

[Unit]
Description=nginx - web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecQuit=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target

Reload system services
systemctl daemon - reload
start service
systemctl start nginx.service
boot
systemctl enable nginx.service

Guess you like

Origin blog.csdn.net/m0_62946761/article/details/130441055