installation method
1. Compile and install the offline installation package
1. Upload the nginx compressed package to the server/opt directory via Xftp
2. Unzip to /usr/local/
tar -zxvf nginx-1.14.2.tar.gz -C /usr/local/
3. Install dependencies
yum -y install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
4. Enter the nginx root directory and execute ./configure
./configure
5. Execute make, and continue to execute make install after completion
1. make
2. make install
6. Enter the /usr/local/nginx/sbin directory, enter ./nginx to start nginx, and check whether there is an nginx process
./nginx
7. Browser access test (IP: port)
- Close the firewall or open the firewall port (nginx defaults to port 8080), choose one
//1. 关闭防火墙
1. systemctl stop firewalld
//2. 防火墙开放8080端口
1. firewall-cmd --zone=public --add-port=8080/tcp --permanent
2. systemctl restart firewalld //重启
2. Browser access
Set up autostart
1. Create a new system service file (nginx.service), and write the following content into the file
vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx service
After=network.target
[Service]
Type=forking
#确认下路径,如果不是在/usr/local则需改成对应路径
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2. Set Nginx to start automatically after booting, and execute in sequence
1. chmod 755 /etc/systemd/system/nginx.service //授权
2. systemctl daemon-reload //加载配置
3. systemctl enable nginx //设置开机自启
3. Start the Nginx service
systemctl start nginx
4. Other common commands
systemctl status nginx //查看nginx状态
systemctl stop nginx //关闭nginx
systemctl restart nginx //重启nginx
Two, yum installation
1. Install nginx source
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2. Use yum to install nginx
yum install -y nginx
3. Start nginx and check the startup status
1. systemctl start nginx //启动nginx
2. systemctl status nginx //查看nginx状态
4. Browser access test (IP: port)
1. Close the firewall or open the firewall port (nginx default port 8080), choose one
//1. 关闭防火墙
1. systemctl stop firewalld
//2. 防火墙开放8080端口
1. firewall-cmd --zone=public --add-port=8080/tcp --permanent
2. systemctl restart firewalld //重启
2. Browser access
Check the version and the path of each file
1. View version
nginx -v
2. View the path of each file
1. rpm -qa | grep nginx
2. rpm -ql nginx-1.22.1-1.el7.ngx.x86_64
Precautions
1. Configuration file
* change as needed tonginx.conf
/etc/nginx/conf.d/default.conf
2. Replace the port
*Pay attention to closing SELinux
, otherwise there may be problems starting
------1. Temporarily close SELinux
setenforce 0
------2. Permanently closed
SELINUX=enforcing
Change toSELINUX=disable
vim /etc/selinux/config
2. Restart the system
reboot