First, install Nginx
Two, Nginx compilation options
Three, Nginx Process management command
Four, nginx configuration file parsing
First, install Nginx
1. Pre-install the required software dependency package
Yum install-y gcc pcre pcre-devel OpenSSL openssl-devel gd gd-devel Perl perl-extutils-embed
2. Download Nginx Source installation package
wget http://nginx.org/download/nginx-1.4.0.tar.gz
3. Unzip the compilation (disable module using parameter--without, compile third party module using parameter--add-module=/path/module)
TAR-XZF nginx-1.4.0.tar.gz-c/usr/src/
Cd/usr/src/nginx-1.4.0/./configure--prefix=/usr/local/nginx--with-ipv6--with-http_ssl_module--with-http_realip _module--with-http_addition_module--with-http_dav_module--with-http_flv_module--with-http_mp4_module-- With-http_gzip_static_module--with-http_perl_module--with-mail--with-mail_ssl_module
4. Installation
Make && make install
After the installation is complete, the program home directory is located in/usr/local/nginx/, the contents of the directory are:
conf, master configuration file directory
HTML, site root directory
logs, log file directory
Sbin, main program directory
Two, Nginx compilation options
1. Default auto-compile items disable option Core:nginx core function,-- Without-httpaccess: IP-based access control--without-http_access_moduleauth basic:http user authentication module--WITHOUT-HTTP_AUTH_BASIC_ Moduleauto index: Automatic Catalog Index--without-http_autoindex_modulebrowser: Describes user agent--without-http_charset_ Modulecharset: recoding page--without-http_charset_moduleempty gif: Storing a picture in memory--without-http_empty_gif_ MODULEFASTCGI:FASTCGI supports--WITHOUT-HTTP_FASTCGI_MODULEGEO: IP variable settings are supported--without-http_geo_ Modulegzip:gzip compression--without-http_gzip_modulelimit requests: Limit Client Connection Frequency--without-http_limit_req_modulelimit conn: Volatile concurrent connection--without-http_limit_conn_modulemap: Setting variable--WITHOUT-HTTP_MAP_ Modulememcached:memcache Support--without-http_memcached_modulereferer: Based on Referer header information filtering--without-http_referer_ Modulerewrite: Use regular expression to rewrite request--without-http_rewrite_modulescgi: Support SCGI Protocol--without-http_scgi_ Moduleupstream: Load Balancing--without-http_upstream_ip_haSh_moduleheaders: Set header information for HTTP Response index: Home log: Custom log
2, add-on module in the built-in module, you need to manually turn on the Open option at compile time embedded Perl: Support perl--with-http_perl_moduleflv: Support Flash Video--with-http_flv_ MODULEGEOIP: Load balancing with IP variables--with-http_geoip_modulegoogle perftools: Support for Google's performance optimization tool--with-google_perftools_modulegzip Precompression: Compress static file--with-http_gzip_static_moduleimage filter: Convert graphics filter--with-http_image_filter_ ModuleMP4: Support mp4--with-http_mp4_modulereal IP: Use Nginx as back-end server--with-http_realip_modulesecure Link: Use key protection page--with-http_secure_link_modulessl: Support Https/ssl--with-http_ssl_modulestub Status: View server Status--with-http_ Stub_status_modulewebdav: Support Webdav--with-http_dav_ Module------------------------------------------Core: Mail agent function--with-mailcore: Mail agent function--without-mail_pop3_ Modulecore: Mail agent function--without-mail_imap_modulecore: Mail agent function--without-mail_smtp_ Module------------------------------------------SSL: Supports SSL/TLS encrypted mail protocol--with-mail_ssl_module
Three, Nginx Process management command
/usr/local/nginx/sbin/nginx #启动主程序/usr/local/nginx/sbin/nginx-c/usr/local/nginx/conf/nginx.conf #指定配置文件启动主程序/usr /local/nginx/sbin/nginx-s Stop #关闭主程序/usr/local/nginx/sbin/nginx-s Reload #重新加载设置
Nginx will save the process number in the/usr/local/nginx/logs/nginx.pid file, you can use the KILL command to send a signal to the process number smooth restart Nginx
Kill-hup ' Cat/usr/local/nginx/logs/nginx.pid '
Four, nginx configuration file parsing
Nginx default configuration file is/usr/local/nginx/conf/nginx.conf, the content is as follows
#user nobody; #设置用户与组worker_processes 1; #启动子进程数 can be ps aux | grep Nginx View # error log file and log level notice,info#error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; #进程号保存文件events { worker_connections 1024;# The number of connections per process that can be processed by the system file handle limit,ulimit}http { include mime.types; #mime. Types for file type definition file default_type application/octet-stream; #默认文件类型 #log_format自定义入职格式, named main #log_format main ' $remote _addr - $remote _user [$time _local] "$request" # ' $status $body_bytes_sent "$http _referer" # ' "$http _user_agent" "$http _x_forwarded_ For "'; #access_log logs/access.log main; #创建访问日志, using the format defined by main sendfile on; #是否调用sendfile () for data replication, Sendfile copy data is done at the kernel level and will be more efficient than normal read, write #tcp_nopush on; #keepalive_timeout 0; #保持连接的超时时间 keepalive_timeout 65; #gzip on; #是否采用压缩功能 to save more traffic when the page is compressed # To define a virtual host using server server { listen 80; #服务器监听的端口 server_ name localhost; #访问域名 &Nbsp; #charset koi8-r; #编码格式, if the page encoding differs from this setting, it will be automatically transcoded #access_log logs/host.access.log main;# Set the access log path for the virtual host and format #对URL进行匹配 location / { root html; #root表示网页根路径, using a relative path, HTML under the Nginx installation path index index.html index.htm; #定义index首页文件, look for index.html first, no then find index.htm } # Error page for setting error codes #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html;location = /50x.html { root html; } # proxy the php scripts to apache listening on 127.0.0.1:80 #访问以php结尾的页面, The request is automatically forwarded to 127.0.0.1:80, and the proxy function #location can be achieved through Proxy_pass ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the php scripts to fastcgi server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param script_filename /scripts$fastcgi_ script_name; # include fastcgi_params; #} # deny access to .htaccess files, if apache ' s document root # concurs with nginx ' s one # #拒绝所有人访问. HT page #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; #监听TLS使用的 # server_name localhost; # ssl on; # Turn on the SSL feature     # &Nbsp; ssl_certificate cert.pem; #指定证书文件, relative path, file must be placed in niginx.conf directory # ssl_certificate_key cert.key; #指定私钥文件, relative path, Files need to be placed in the same directory as the niginx.conf # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers high:!anull:! md5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
Source installation nginx and configuration file detailed