nginx (1), nginx entry

1. What is nginx
Nginx ("engine x") is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP server. Nginx was developed by Igor Sysoev for the second most visited Rambler.ru site in Russia. It releases the source code under a BSD-like license and is known for its stability, rich feature set, sample configuration files, and low consumption of system resources. nginx official website: http://nginx.org/  .
Alibaba has carried out secondary development of nginx named Tengine, which makes the function more powerful. Official website: http://tengine.taobao.org/
 
Second, the advantages of nginx
  • Lightweight
  • High scalability, it is modular development
  • High reliability, the master process can quickly switch to a new worker process after a worker process fails
  • low memory consumption
  • hot deployment
  • Cacheless reverse proxy acceleration, simple load balancing and fault tolerance
  • Process static files, index files, and automatic indexing; open file descriptor buffering
  • Support for SSL and TLSSNI
 
3. Download and install nginx
1. Download nginx , preferably the stable version. Official website download address: http://nginx.org/en/download.html,

 

wget http://nginx.org/download/nginx-1.8.0.tar.gz
2. Decompression
 
tar -zxvf nginx-1.8.0.tar.gz
3. nginx1.8.0 needs to pre-install the PCRE library to support the rewrite module
yum install pcre*
4. nginx1.8.0 needs to be pre-installed with openssl to require ssl
yum install openssl*
5. Set configuration information
./configure  --prefix=/mytest/ngnix_test/nginx_bin --with-http_ssl_module  --with-http_stub_status_module  --with-pcre
illustrate:
 
./configure  
--prefix=/mytest/ngnix_test/nginx_bin #Specify the installation directory
--with-http_ssl_module                 #支持https
--with-http_stub_status_module #Support nginx status query
--with-pcre #Specify rewrite rewrite function
6. Compile
make
7. Installation
make install
Fourth, compile and install configure parameter description
Supplementary explanation for the configuration information of 3.5 settings
--prefix= points to the installation directory
--sbin-path point to (execute) the program file (nginx)
--conf-path= points to the configuration file (nginx.conf)
--error-log-path= point to error log directory
--pid-path= point to the pid file (nginx.pid)
--lock-path= points to the lock file (nginx.lock) (the installation file is locked to prevent the installation file from being used by others or misoperation by yourself.)
--user= specifies the unprivileged user the program runs as
--group= Specifies the unprivileged user group when the program runs
--builddir= points to the build directory
--with-rtsig_module enable rtsig module support (real-time signals)
--with-select_module Enable select module support (a polling mode, not recommended for use in high-load environments) Disable: --without-select_module
--with-poll_module Enable poll module support (the function is the same as select, the same as the select feature, it is a polling mode, it is not recommended to use in a high-load environment)
--with-file-aio Enable file aio support (an APL file transfer format)
--with-ipv6 enable ipv6 support
--with-http_ssl_module Enable ngx_http_ssl_module support (to support https requests, openssl must be installed)
--with-http_realip_module enable ngx_http_realip_module support (this module allows changing the client's IP address value from request headers, default is off)
--with-http_addition_module enables ngx_http_addition_module support (as an output filter, supports incomplete buffering, and responds to requests in parts)
--with-http_xslt_module Enable ngx_http_xslt_module support (filtering transform XML requests)
--with-http_image_filter_module Enable ngx_http_image_filter_module support (a filter for transmitting JPEG/GIF/PNG images) (default is not enabled. Used by gd library)
--with-http_geoip_module Enable ngx_http_geoip_module support (this module creates ngx_http_geoip_module variable based on client IP address matched with MaxMind GeoIP binary)
--with-http_sub_module enable ngx_http_sub_module support (allows to replace some text in nginx response with some other text)
--with-http_dav_module Enable ngx_http_dav_module support (add PUT, DELETE, MKCOL: create collection, COPY and MOVE methods) is disabled by default and needs to be compiled and enabled
--with-http_flv_module Enable ngx_http_flv_module support (provides time-based offset files for seeking memory usage)
--with-http_gzip_static_module Enable ngx_http_gzip_static_module support (online real-time compressed output data stream)
--with-http_random_index_module enable ngx_http_random_index_module support (randomly pick a directory index from the directory)
--with-http_secure_link_module enable ngx_http_secure_link_module support (computes and checks required secure link urls)
--with-http_degradation_module enable ngx_http_degradation_module support (allow to return 204 or 444 code in low memory conditions)
--with-http_stub_status_module enable ngx_http_stub_status_module support (get nginx working status since last start)
--without-http_charset_module disable ngx_http_charset_module support (re-encode web pages, but only in one direction -- server-to-client, and only one byte encoding can be re-encoded)
--without-http_gzip_module disable ngx_http_gzip_module support (this module has the same function as -with-http_gzip_static_module)
--without-http_ssi_module disables ngx_http_ssi_module support (this module provides a filter that handles server include files (SSI) on the input side, the list of supported SSI commands is currently incomplete)
--without-http_userid_module disables ngx_http_userid_module support (this module handles cookies used to determine subsequent client requests)
--without-http_access_module disable ngx_http_access_module support (this module provides a simple host-based access control. Allow/deny based on ip address)
--without-http_auth_basic_module disables ngx_http_auth_basic_module
--without-http_autoindex_module disable disable ngx_http_autoindex_module support (This module is used to automatically generate directory listings, and only make requests when the ngx_http_index_module module does not find an index file.)
--without-http_geo_module disable ngx_http_geo_module support (create some variables whose value depends on client's IP address)
--without-http_map_module disable ngx_http_map_module support (set configuration variable with arbitrary key/value pair)
--without-http_split_clients_module disable ngx_http_split_clients_module support (this module is used to divide users based on certain conditions. Conditions such as: ip address, headers, cookies, etc.)
--without-http_referer_module disable disable ngx_http_referer_module support (this module is used to filter requests and reject requests with incorrect Referer values ​​in the header)
--without-http_rewrite_module disables ngx_http_rewrite_module support (this module allows to use regular expressions to change URIs, and to redirect and choose configuration based on variables. If this option is set at the server level, they will take effect before location. If there are more changes at location Further rewriting rules, the rules of the location part will still be executed. If the URI rewriting is caused by the rules of the location part, then the location part will be executed again as a new URI. This loop will be executed 10 times, and then Nginx will return a 500 error.)
--without-http_proxy_module disable ngx_http_proxy_module support (for proxy servers)
--without-http_fastcgi_module disables ngx_http_fastcgi_module support (this module allows Nginx to interact with the FastCGI process and to control the FastCGI process by passing parameters.) FastCGI is a resident public gateway interface.
--without-http_uwsgi_module disable ngx_http_uwsgi_module support (this module is used for medical uwsgi protocol, uWSGI server related)
--without-http_scgi_module Disable ngx_http_scgi_module support (this module is used to enable SCGI protocol support, SCGI protocol is a replacement for CGI protocol. It is an application and HTTP service interface standard. It is somewhat like FastCGI but his design is easier to implement. )
--without-http_memcached_module disable ngx_http_memcached_module support (this module is used to provide simple caching to improve system efficiency)
-without-http_limit_zone_module disables ngx_http_limit_zone_module support (this module can control the number of concurrent connections for sessions for conditions)
--without-http_limit_req_module disables ngx_http_limit_req_module support (this module allows you to limit the number of requests to an address with a given session or a specific event)
--without-http_empty_gif_module disables ngx_http_empty_gif_module support (this module keeps a 1*1 transparent GIF image in memory and can be called very quickly)
--without-http_browser_module disables ngx_http_browser_module support (this module is used to create values ​​that depend on request headers. If the browser is modern, $modern_browser is equal to the value assigned by the modern_browser_value directive; if the browser is old, $ancient_browser is equal to the ancient_browser_value directive assigned The value of ; if the browser is any version in MSIE, $msie is equal to 1)
--without-http_upstream_ip_hash_module disable ngx_http_upstream_ip_hash_module support (this module is used for simple load balancing)
--with-http_perl_module enable ngx_http_perl_module support (this module enables nginx to use perl directly or call perl via ssi)
--with-perl_modules_path= set perl module path
--with-perl= set the perl library file path
--http-log-path= set access log path
--http-client-body-temp-path= set http client request temporary file path
--http-proxy-temp-path= set http proxy temporary file path
--http-fastcgi-temp-path= set http fastcgi temporary file path
--http-uwsgi-temp-path= set http uwsgi temporary file path
--http-scgi-temp-path= set http scgi temporary file path
-without-http disable http server function
--without-http-cache disable http cache feature
--with-mail enable POP3/IMAP4/SMTP proxy module support
--with-mail_ssl_module enable ngx_mail_ssl_module support
--without-mail_pop3_module Disable the pop3 protocol (POP3 is the third version of the Post Office Protocol, it is a protocol that specifies how personal computers connect to a mail server on the Internet to send and receive mail. It is the first offline protocol standard for Internet e-mail, The POP3 protocol allows users to store mail from the server to the local host, and delete or save the mail on the mail server according to the operation of the client. POP3 protocol is a member of the TCP/IP protocol family, mainly used to support the use of client Remotely manage email on the server)
--without-mail_imap_module Disable the imap protocol (a mail acquisition protocol. Its main function is that the mail client can obtain mail information from the mail server, download mail, etc. through this protocol. The IMAP protocol runs on the TCP/IP protocol. On, the port used is 143. The main difference between it and the POP3 protocol is that the user can directly operate the mail on the server through the client without downloading all the mails.)
--without-mail_smtp_module disables the smtp protocol (SMTP is the Simple Mail Transfer Protocol, which is a set of rules used to transmit mail from source address to destination address, which controls the transfer method of letters. The SMTP protocol belongs to the TCP/IP protocol family , which helps each computer find its next destination when sending or relaying letters.)
--with-google_perftools_module Enable ngx_google_perftools_module support (for debugging, to profile program performance bottlenecks)
--with-cpp_test_module enable ngx_cpp_test_module support
--add-module= Enable external module support
--with-cc= point to the C compiler path
--with-cpp= point to the C preprocessor path
--with-cc-opt= Set C compiler parameters (PCRE library, you need to specify --with-cc-opt=”-I /usr/local/include”, if you use the select() function, you need to add a file descriptor at the same time Quantity, which can be specified with --with-cc-opt=”-D FD_SETSIZE=2048”.)
--with-ld-opt= Set connection file parameters. (PCRE library, need to specify --with-ld-opt=”-L /usr/local/lib”.)
--with-cpu-opt= specify the CPU to compile, available values ​​are: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, amd64, sparc32, sparc64, ppc64
--without-pcre disable pcre library
--with-pcre enable pcre library
--with-pcre= point to the pcre library file directory
--with-pcre-opt= set additional parameters for pcre library at compile time
--with-md5= points to the md5 library file directory (the fifth edition of the message digest algorithm to provide message integrity protection)
--with-md5-opt= set additional parameters for md5 library at compile time
--with-md5-asm use md5 assembly source
--with-sha1= points to the sha1 library directory (digital signature algorithm, mainly used for digital signatures)
--with-sha1-opt= set additional parameters for sha1 library at compile time
--with-sha1-asm use sha1 assembly source
--with-zlib= point to the zlib library directory
--with-zlib-opt= set additional parameters for zlib at compile time
--with-zlib-asm= Use zlib assembly source for optimization for the specified CPU, the CPU type is pentium, pentiumpro
--with-libatomic provides a framework for implementing atomic memory update operations
--with-libatomic= point to the libatomic_ops installation directory
--with-openssl= point to the openssl installation directory
--with-openssl-opt set additional parameters for openssl at compile time
--with-debug enable debug logging
Five, nginx directory introduction
cd /mytest/ngnix_test/nginx_bin,
See the installed nginx directory
conf configuration file, common configuration of nginx
html web page file, the page under nginx, can be configured here
logs log files, nginx process files, etc.
sbin main binary program, nginx program
 
6. Commonly used nginx operation commands
1. Start nginx
cd /mytest/ngnix_test/nginx_bin/sbin
./nginx
 At this point, /mytest/ngnix_test/nginx_bin/conf/nginx.conf will be loaded by default
 
specify conf 
./nginx -c xxNginx.conf
 
2. Restart
./nginx -s reload
3. Close
./nginx -s stop
4. Stop running
 
ps -ef | grep nginx # Find the main process number
cat /mytest/ngnix_test/nginx_bin/logs/nginx.pid #nginx process id number
kill -9 NGINX_PID# Force kill the nginx process according to the nginx pid
 
7. Summary
Nginx is a great high-performance http server, usually used as an html server, load balancing server, and many Internet companies have already used it in production. Well worth the time to research.
 
#The next article introduces the common configuration of nginx
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326223813&siteId=291194637