Nginx
Web server
Reverse Proxy
Web
Mail
Modular design
Tengine
Varrnish,squid
Nginx:cache (disk)
Httpd:cache (Disk,memory)
Nginx Basic HTTP Server features:
1. Handling static files, index files and automatic indexing; Open File descriptor cache
2. Use cache to accelerate reverse proxy, simple load balancing and fault tolerance
3. Cache acceleration support for remote fastcgi,uwsgi,scgi, and memcached services; simple load balancing and fault tolerance
4. Modular architecture, filters include gzip compression, ranges support, chunked response, Xslt,ssi, and image scaling. In an SSI filter, a page containing multiple SSI can be processed in parallel if processed via fastcgi or reverse proxy
5. Support Ssl,tls SNI
Nginx Other HTTP Server features
1. Name and IP-based virtual host, Port-based virtual host not supported
2.keep-alive and pipelined connection support
3. Flexible configuration
4. Reload the configuration and the online upgrade, do not need the terminal is processing the request;/nginx-s Reload
5. Custom access log format with cached log write operations and fast log rotation
6.3XX-5XX Error code redirection
7. Rewrite (rewrite) module: Use regular expressions to change URLs
8. Perform different functions according to the client address
9. Access control based on client IP address and HTTP Basic authentication mechanism
10. Support Authentication HTTP Referer
11. Support for put, DELETE, MKCOL, copy, and Move methods
12. Support for FLV streams and MP4 streams
13. Speed Limit
14. Number of simultaneous connections or requests from the same address
15. Embedded in the Perl language
Architecture and Scalability
1. One master process and multiple worker processes, the worker process runs as a non-privileged user
2. Supported event Mechanisms: Kqueue (FreeBSD 4.1+), Epoll (Linux 2.6+), RT Signals (Linux 2.2.19+),/dev/poll (Solaris 7 11/99+), Event ports ( Solaris 10), select, and poll
3. Numerous supported Kqueue features include Ev_clear, ev_disable (temporary Forbidden event), Note_lowat, ev_eof, number of available data, error codes
4. Support Sendfile (FreeBSD 3.1+,linux 2.2+, Mac OS X 10.5+), sendfile64 (Linux 2.4.21+), and Sendfilev (Solaris 87/o1+)
5. Document AIO (FreeBSD 4.3+,linux 2.6.22+)
6.DIRECTIO (FreeBSD 4.4+,linux 2.4+,solaris 2.6+,mac OS X)
7. Support Accept-filters (FreeBSD 4.1+,netbsd 5.0+) and tcp_defer_accept (Linux 2.4+)
8.1 Inactive HTTP keep-alive connections take up only 2.5M of memory in a month
9. Avoid data copy operations whenever possible
The Nginx process consists of a master process and multiple worker processes, and if the cache is configured, there is also the cache loader process (caches loader) and the cache manager process (cached manager), which is initiated by the root user. Other processes, such as worker, are run by non-privileged users
The main process mainly accomplishes the following tasks:
1. Read and verify configuration information
2. Create, bind, and close sockets
3. Number of worker processes to start, terminate, and maintain
4. Re-configured work features without terminating the service
5. Control non-disruptive program upgrades, enable new binaries and roll back to older versions when needed
6. Reopen the log file
7. Compiling the embedded Perl script
Main tasks performed by the worker process:
1. Receive, incoming, and process connections from the client
2. Provide reverse proxy and filtering function
3.nginx any other tasks that can be done
The main tasks of the cache loader process
1. Check cache objects in the cache store
2. Using cache metadata to establish an in-memory database
Key tasks for the cache manager process
1. Cache invalidation and expiration check
Nginx configuration has several different contexts: Main, HTTP, server, upstream, and location (as well as mail Service reverse proxy)
Installing Nginx
Add Nginx User
# groupadd-r Nginx
# Useradd-r-G Nginx
Compiling and installing
#./configure--prefix=/usr/local/nginx--sbin-path=/usr/sbin/nginx--conf-path=/etc/nginx/nginx.conf-- Error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log--pid-path=/var/run/nginx/ Nginx.pid--lock-path=/var/lock/nginx.lock--user=nginx--group=nginx--with-http_ssl_module--with-http_flv_module --with-http_stub_status_module--with-http_gzip_static_module--http-client-body-temp-path=/var/tmp/nginx/client --http-fastcgi-temp-path=/var/tmp/nginx/fcgi--http-proxy-temp-path=/var/tmp/nginx/proxy--http-uwsgi-temp-path= /var/tmp/nginx/uwsgi--http-scgi-temp-path=/var/tmp/nginx/scgi--with-pcre
# Make && make install
Provide a startup script for Nginx
# Vim/etc/rc.d/init.d/nginx
#!/bin/bash
#
#chkconfig: 2345 85 15
#description: Nginx is HTTP server
#
# 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/sbin/nginx"
prog= ' basename $nginx '
Nginx_conf_file= "/etc/nginx/nginx.conf"
Lockfile= "/var/lock/subsys/nginx"
Nginx_pid= "/var/run/nginx/nginx.pid"
[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx
Mk_dir () {
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
If [-e $nginx _pid];then
echo "Nginx already running ..."
Exit 1
Fi
Echo-n $ "Starting $prog:"
Mk_dir
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
}
Reload () {
Configtest | | Return $?
Echo-n $ "Reloading $prog:"
Killproc $nginx-hup
Retval=$?
Echo
}
Configtest () {
$nginx-T-C $nginx _conf_file
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart
Configtest | | Return $?
Stop
Sleep 1
Start
;;
Reload
Reload
;;
Status
Status $prog
Retval=$?
;;
Configtest)
Configtest
;;
*)
echo $ "Usage: $ {start|stop|status|restart|reload|configtest}"
Exit 2
;;
Esac
Add as a service and set the startup level to 2345
# chmod +x/etc/rc.d/init.d/nginx
# chkconfig--add Nginx
# chkconfig--level 2345 Nginx on
Nginx_1_ Foundation and Installation