Table of contents
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 gccyum install - y pcre pcre - devel # install perl libraryyum 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/nginxmakemake 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 serverAfter=network.target remote-fs.target nss-lookup.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.confExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s stopExecQuit=/usr/local/nginx/sbin/nginx -s quitPrivateTmp=true[Install]WantedBy=multi-user.target
Reload system services
systemctl daemon - reload
start service
systemctl start nginx.service
boot
systemctl enable nginx.service