Source code compilation and installation of Nginx services and access control (practical! )
About Nginx High Performance, Lightweight Web Services Software
high stability
Low system resource consumption
High throughput for HTTP concurrent connections
A single physical server can support 30000 ~ 50000 concurrent requests Nginx compilation and installation 1. The host machine shares the required toolkits
2. VM mount shared directory [root@localhost ~]# smbclient -L //192.168.100.50/Enter SAMBA\root's password: OS=[Windows 10 Enterprise LTSC 2019 17763] Server=[Windows 10 Enterprise LTSC 2019 6.3] Sharename Type Comment --------- ---- ------- IPC$ IPC remote IPC share Disk tools Disk Users Disk Connection to 192.168.100.50 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)NetBIOS over TCP disabled -- no workgroup available[root@localhost ~]# mkdir /mnt/tools[root@localhost ~]# mount.cifs //192.168.100.50/tools /mnt/tools/Password for root@//192.168.100.50/tools: [root@localhost ~]# cd /mnt/tools/[root@localhost tools]# lsawstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7 picture.jpgcronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideahahau2018.rar john-1.8.0.tar.gz LNMP[root@localhost tools]#3. Decompress Nginx source package [root@localhost tools]# cd LNMP/[root@localhost LNMP]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.20.tar.gz[root@localhost LNMP]#zxvf nginx-1.12.2.tar.gz -C /opt/...// Omit the decompression process 4. Install the environment package required to compile Nginx [root@localhost LNMP]# yum -y install gcc gcc-c++ pcre-devel zlib-devel.........// Omit installation [root@localhost LNMP]#5. Create a new program user nginx[root@localhost LNMP]# useradd -M -s /sbin/nologin nginx //-M, Do not create home directory [root@localhost LNMP]# id nginx //View nginx users uid=1001(nginx) gid=1001(nginx) group =1001(nginx)[root@localhost LNMP]#6. Configure Nginx services [root@ localhost LNMP]# cd /opt/nginx-1.12.2/[root@localhost nginx-1.12.2]# lsauto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src[root@localhost nginx-1.12.2]# ./ configure \> --prefix=/usr/local/nginx \ //install path> --user=nginx \ //group=nginx \ //group> --with-http_stub_status_module //Open statistics module.........// Omit configuration 7. Compile and install Nginx service [root@localhost nginx-1.12.2]# make && make install.........// Omit compilation process [root@localhost nginx-1.12.2]# 8. Optimize nginx command execution path [root@localhost nginx-1.12.2]# cd /usr/local/nginx/[root@ localhost nginx]# lsconf html logs sbin[root@localhost nginx]# cd sbin/[root@ localhost sbin]# lsnginx[root@localhost sbin]# ln -s /usr/local/nginx/sbin/[root@localhost sbin]# 9. Start nginx service [root@localhost sbin] localhost sbin]# nginx -t //Check test configuration file nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@localhost sbin]# nginx //open service [root@localhost sbin]# netstat -ntap| grep 80 //View TCP port 80 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 52709/nginx: master [root@localhost sbin]#10. Turn off firewall and enhanced security features [root@localhost sbin]# systemctl stop firewall.service //turn off firewall [root@localhost sbin]# setenforce 0 //Turn off enhanced security [root@localhost sbin]# 11. Install elinks tool, test nginx service [root@localhost sbin]# yum install elinks -y //Installation Tools.............................................................................. omitting installation [root@localhost sbin]# [root@localhost sbin]# elinks http://localhost //Test access to nginx services
12. Test whether you can access nginx service with browser (access successful)
Nginx service optimization 1.nginx service basics [root@localhost sbin]# killall -s QUIT nginx //stop service [root@localhost sbin]# killall -3 nginx //stop service [root@localhost sbin]# killall -s HUP nginx //overloaded services [root@localhost sbin]# killall -1 nginx //overloaded services [root@localhost sbin]# nginx //Start the service 2. Create a script for the management service [root@localhost sbin]# vim /etc/init.d/nginx#!/ bin/bash# chkconfig: - 99 20# description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1esacexit 0[root@localhost sbin]# chmod +x /etc/init.d/nginx //add execute permissions [root@localhost sbin]# chkconfig --add nginx //add to make the system recognize [root@localhost sbin]# 3. test service administration script [root@localhost sbin]# service nginx stop //stop service [root@localhost sbin]# netstat -ntap| grep 80 //View port 80, none [root@localhost sbin]# service nginx start //open service [root@localhost sbin]# netstat -ntap| grep 80 //check port 80, there is tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 53614/nginx: master [root@localhost sbin]# 4. Modify configuration file to enable statistics [root@localhost sbin]# vim /usr/local/nginx/conf/nginx.conf location / { root html; index index.html index.htm; } location /status { stub_status on; access_log off; # service nginx stop[root @ localhost sbin]#service nginx start [root @ localhost sbin]#5. Test statistics
Nginx service access control 1. Modify the configuration file to enable password access [root@localhost sbin]# vim /usr/local/nginx/conf/nginx.conf location / { auth_basic "secret"; auth_basic_user_file /usr/local/nginx/passwd.db; root html; index index.html index.htm; } location /status { stub_status on; access_log off; }[root@localhost sbin]#2. Install password access tools [root@localhost sbin]# yum install httpd-tools -y.........// Omit installation [root@localhost sbin]# 3. Create user and password to access login [root@localhost sbin]# htpasswd -c/usr/local/nginx/passwd.db test New password: Re-type new password: Adding password for user test[root@localhost sbin]#cat/usr/local/nginx/passwd.db test:$apr1$od5a34WH$MduYUJbQ2W0oihB0Bs/bx. [root@localhost sbin]# [root@localhost sbin]# service nginx stop[root@localhost sbin]# service nginx start [root@localhost sbin]# 4. Test access control (success)