1. First upload the Nginx installation package to the/home directory in the virtual machine
2. Create a combined user for easy Nginx operation without compromising Linux security
Groupadd-r Nginx
Useradd-r-G nginx-m nginx
3. After entering the/home directory, unzip
TAR–ZXVF tengine-2.1.0.tar.gz
4. After the decompression is complete, go to the Tengine directory
5. Pre-compile:./configure--prefix=/usr/tengine-2.1.0, if required gcc etc can be installed under Yum
6. Compile and install after precompilation: Make && do install
7. Configure Nginx for the system service, in order to facilitate the management, that is, in the/etc/rc.d/init.d/directory to create a text file Nginx, paste the following content inside:
#!/bin/sh
#
# Nginx-this script starts and stops the Nginx daemon
#
# Chkconfig:-85 15
# Description:nginx is an HTTP (s) server, HTTP (s) reverse \
# Proxy and IMAP/POP3 proxy server
# Processname:nginx
# config:/etc/nginx/nginx.conf
# config:/etc/sysconfig/nginx
# Pidfile:/var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source Networking configuration.
. /etc/sysconfig/network
# Check that networking are up.
["$NETWORKING" = "no"] && exit 0
nginx= "/usr/tengine-2.1.0/sbin/nginx"
prog=$ (basename $nginx)
Nginx_conf_file= "/usr/tengine-2.1.0/conf/nginx.conf"
[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx
Lockfile=/var/lock/subsys/nginx
Make_dirs () {
# Make required Directories
User= ' Nginx-v 2>&1 | grep "Configure arguments:" | Sed ' s/[^*]*--user=\ ([^]*\). */\1/g '-'
Options= ' $nginx-v 2>&1 | grep ' Configure arguments: '
for opt in $options; Do
If [' Echo $opt | grep '. *-temp-path ']; Then
Value= ' echo $opt | Cut-d "="-F 2 '
if [!-D "$value"]; Then
# echo "Creating" $value
Mkdir-p $value && chown-r $user $value
Fi
Fi
Done
}
Start () {
[-X $nginx] | | Exit 5
[-F $NGINX _conf_file] | | Exit 6
Make_dirs
Echo-n $ "Starting $prog:"
Daemon $nginx-C $NGINX _conf_file
Retval=$?
Echo
[$retval-eq 0] && Touch $lockfile
Return $retval
}
Stop () {
Echo-n $ "Stopping $prog:"
Killproc $prog-quit
Retval=$?
Echo
[$retval-eq 0] && rm-f $lockfile
Return $retval
}
Restart () {
Configtest | | Return $?
Stop
Sleep 1
Start
}
Reload () {
Configtest | | Return $?
Echo-n $ "Reloading $prog:"
Killproc $nginx-hup
Retval=$?
Echo
}
Force_reload () {
Restart
}
Configtest () {
$nginx-T-C $NGINX _conf_file
}
Rh_status () {
Status $prog
}
Rh_status_q () {
Rh_status >/dev/null 2>&1
}
Case "$" in
Start
Rh_status_q && Exit 0
$
;;
Stop
Rh_status_q | | Exit 0
$
;;
Restart|configtest)
$
;;
Reload
Rh_status_q | | Exit 7
$
;;
Force-reload)
Force_reload
;;
Status
Rh_status
;;
Condrestart|try-restart)
Rh_status_q | | Exit 0
;;
*)
echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
Exit 2
Esac
8. Modify the Nginx File execution permissions
chmod +x Nginx
9. Add the file to the system service go: Chkconfig--add nginx, if you see if add success, then use the command: Chkconfig--list nginx
10. Start the Service command: service Nginx start
11. Configure the configuration file in the nginx.conf file in conf (note the curly braces)
12. Module Ngx_http_auth_basic_module allows the use of the HTTP Basic authentication protocol to authenticate user names and passwords to restrict access to resources.
Location/{
Auth_basic "closed site";
Auth_basic_user_file/var/users;
}
The HTPASSWD command in the Apache release package to create the User_file file
Htpasswd-c-m/var/users username
AutoIndex List the file index of the current directory in the browser
AutoIndex on;
The process of installing a startup Nginx under Linux