Nginx之一:编译安装及基础应用

一、Nginx简介

Nginx是一个轻量级的,高性能的Web服务器以及反向代理和邮箱(IMAP/POP3)代理服务器。它运行在UNIX,GNU/Linux,BSD各种版本,Mac OS X,Solaris和Windows。据统计,6%的网站使用Nginx Web服务器。Nginx是少数能处理C10K问题的服务器之一。跟传统的服务器不同,Nginx不依赖线程来处理请求。相反,它使用了更多的可扩展的事件驱动(异步)架构。Nginx为一些高流量的网站提供动力,比如WordPress,人人网,腾讯,网易等。

特点:

模块化,目前只能将模块编译进Nginx,暂时不支持动态装卸载模块.(httpd优势)

可靠性,一个主进程(master)控制多个工作进程(worker),工作进程响应用户多个请求(httpd劣势)

低内存消耗,(httpd劣势)

支持热部署,(httpd一样)

支持事件驱动I/O,AI/O,支持mmap(httpd2.4才支持event,劣势)

Nginx由一个master进程生成多个worker进程,每个worker进程接收用户请求,支持sendfile,AIO,mmap。

Nginx官网:https://www.nginx.com,下载地址:http://nginx.org/en/download.html

二、编译安装

1、下载压缩包,并解压到当前目录,安装依赖组件

#wget http://nginx.org/download/nginx-1.10.0.tar.gz

#tar xf nginx-1.10.0.tar.gz

#yum -y install pcre-devel zlib-devel openssl-devel

注:pcre-devel(url重写需要的组件,支持较强扩展性),openssl-devel(openssl依赖的组件)

2、创建启动Nginx用户及组

#groupadd -r nginx           #创建一个nginx系统组

#useradd -g nginx -r nginx   #将nginx用户加入nginx组

3、Nginx,configure预编译之前,常见选项/参数说明

# cd nginx-1.10.0

#./configure --help
 
  --help                             print this message            #帮助
 
  --prefix=PATH                      set installation prefix        #安装路径
  --sbin-path=PATH                   set nginx binary pathname        #主程序安装路径
  --modules-path=PATH                set modules path                #模块安装路径
  --conf-path=PATH                   set nginx.conf pathname        #主配置文件安装路径
  --error-log-path=PATH              set error log pathname        #错误日志路径
  --pid-path=PATH                    set nginx.pid pathname        #pid文件路径
  --lock-path=PATH                   set nginx.lock pathname        #锁文件路径
 
  --user=USER                        set non-privileged user for    #nginx启动时work进程以什么身份运行
                                     worker processes
  --group=GROUP                      set non-privileged group for    #nginx启动时work进程以什么组运行
                                     worker processes
 
  --build=NAME                       set build name             #指定编译的名称
  --builddir=DIR                     set build directory        #指定编译的目录
                                                                     #with的是默认没启用的模块,with后启用
                                                                     #without的是默认启动的模块,without后关闭
  --with-select_module               enable select module            #开起select模块
  --without-select_module            disable select module           #关闭select模块
  --with-poll_module                 enable poll module              #开起poll模块
  --without-poll_module              disable poll module             #关闭poll模块
 
  --with-threads                     enable thread pool support        #启用线程池
 
  --with-file-aio                    enable file AIO support        #开起文件AIO功能,一般用来提高图片站读i/o操作
  --with-ipv6                        enable IPv6 support                #开起ipv6支持
 
  --with-http_ssl_module             enable ngx_http_ssl_module        #启用ssl模块
  --with-http_v2_module              enable ngx_http_v2_module        #源自spdy协议,优先请求浏览器最继续的内容
  --with-http_realip_module          enable ngx_http_realip_module    #反向代理时把真实访问ip传给后端
  --with-http_addition_module        enable ngx_http_addition_module    #在页面后添加文本
  --with-http_xslt_module            enable ngx_http_xslt_module        #在响应XML文件时,转为一个或多个XSLT样式
  --with-http_xslt_module=dynamic    enable dynamic ngx_http_xslt_module    #动态的xslt模块
  --with-http_image_filter_module    enable ngx_http_image_filter_module    #开启图片转换功能,依赖 libgd 库,能够对图片进行转换格式,尺寸等
   
  --with-http_image_filter_module=dynamic        #动态的image_filter模块
                                     enable dynamic ngx_http_image_filter_module
  --with-http_geoip_module           enable ngx_http_geoip_module    #开启GeoIP功能,需要geoIP 数据库的支持
  --with-http_geoip_module=dynamic   enable dynamic ngx_http_geoip_module    #动态geoip模块
  --with-http_sub_module             enable ngx_http_sub_module            #sub模块,用来替换相应包指定内容
  --with-http_dav_module             enable ngx_http_dav_module            #开启WebDAV功能,此方法可以开启PUT、DELETE、COPY、MKCOL、MOVE等HTTP方法,建议关闭
   
  --with-http_flv_module             enable ngx_http_flv_module            #流媒体模块
  --with-http_mp4_module             enable ngx_http_mp4_module            #mp4模块
  --with-http_gunzip_module          enable ngx_http_gunzip_module    #开启gzip方式传输模式,能够大大减少带宽消耗
  --with-http_gzip_static_module     enable ngx_http_gzip_static_module    #压缩静态页面的gizp模块
  --with-http_auth_request_module    enable ngx_http_auth_request_module   #基于请求的返回结果来控制用户鉴权
  --with-http_random_index_module    enable ngx_http_random_index_module   #响应用户以 “/” 结尾的请求,并在该目录下随机选择一个文件作为index文件。此模块先于 ngx_http_index_module 被执行
   
  --with-http_secure_link_module     enable ngx_http_secure_link_module    #开启安全链接功能。防盗链用
  --with-http_degradation_module     enable ngx_http_degradation_module    #内存不足时,Nginx将返回204或444给客户端
  --with-http_slice_module           enable ngx_http_slice_module        #开启切片模块,对大文件切片用
  --with-http_stub_status_module     enable ngx_http_stub_status_module    #nginx状态页面模块
 
  --without-http_charset_module      disable ngx_http_charset_module    #下面都是默认安装的模块,有需要可以关闭
  --without-http_gzip_module         disable ngx_http_gzip_module
  --without-http_ssi_module          disable ngx_http_ssi_module
  --without-http_userid_module       disable ngx_http_userid_module
  --without-http_access_module       disable ngx_http_access_module
  --without-http_auth_basic_module   disable ngx_http_auth_basic_module
  --without-http_autoindex_module    disable ngx_http_autoindex_module
  --without-http_geo_module          disable ngx_http_geo_module
  --without-http_map_module          disable ngx_http_map_module
  --without-http_split_clients_module disable ngx_http_split_clients_module
  --without-http_referer_module      disable ngx_http_referer_module
  --without-http_rewrite_module      disable ngx_http_rewrite_module
  --without-http_proxy_module        disable ngx_http_proxy_module
  --without-http_fastcgi_module      disable ngx_http_fastcgi_module
  --without-http_uwsgi_module        disable ngx_http_uwsgi_module
  --without-http_scgi_module         disable ngx_http_scgi_module
  --without-http_memcached_module    disable ngx_http_memcached_module
  --without-http_limit_conn_module   disable ngx_http_limit_conn_module
  --without-http_limit_req_module    disable ngx_http_limit_req_module
  --without-http_empty_gif_module    disable ngx_http_empty_gif_module
  --without-http_browser_module      disable ngx_http_browser_module
  --without-http_upstream_hash_module
                                     disable ngx_http_upstream_hash_module
  --without-http_upstream_ip_hash_module
                                     disable ngx_http_upstream_ip_hash_module
  --without-http_upstream_least_conn_module
                                     disable ngx_http_upstream_least_conn_module
  --without-http_upstream_keepalive_module
                                     disable ngx_http_upstream_keepalive_module
  --without-http_upstream_zone_module
                                     disable ngx_http_upstream_zone_module
 
  --with-http_perl_module            enable ngx_http_perl_module    #开起perl模块
  --with-http_perl_module=dynamic    enable dynamic ngx_http_perl_module    #动态perl模块
  --with-perl_modules_path=PATH      set Perl modules path
  --with-perl=PATH                   set perl binary pathname
 
  --http-log-path=PATH               set http access log pathname    #访问日志路径
  --http-client-body-temp-path=PATH  set path to store                #客户端上传内容临时存放位置,路径不存在则必须先创建
                                     http client request body temporary files
  --http-proxy-temp-path=PATH        set path to store                #作为代理服务器代理内容临时存放位置
                                     http proxy temporary files
  --http-fastcgi-temp-path=PATH      set path to store                #fastcgi协议工作时所需临时目录
                                     http fastcgi temporary files
  --http-uwsgi-temp-path=PATH        set path to store                #uwsgi协议工作时所需临时目录
                                     http uwsgi temporary files
  --http-scgi-temp-path=PATH         set path to store                #scgi协议工作时所需临时目录
                                     http scgi temporary files
 
  --without-http                     disable HTTP server
  --without-http-cache               disable HTTP cache
 
  --with-mail                        enable POP3/IMAP4/SMTP proxy module    #开起mail模块
  --with-mail=dynamic                enable dynamic POP3/IMAP4/SMTP proxy module    #开起mail动态模块
  --with-mail_ssl_module             enable ngx_mail_ssl_module
  --without-mail_pop3_module         disable ngx_mail_pop3_module
  --without-mail_imap_module         disable ngx_mail_imap_module
  --without-mail_smtp_module         disable ngx_mail_smtp_module
 
  --with-stream                      enable TCP/UDP proxy module    #stream模块用于tcp/udp和负载均衡
  --with-stream=dynamic              enable dynamic TCP/UDP proxy module    #动态stream模块
  --with-stream_ssl_module           enable ngx_stream_ssl_module
  --without-stream_limit_conn_module disable ngx_stream_limit_conn_module
  --without-stream_access_module     disable ngx_stream_access_module
  --without-stream_upstream_hash_module
                                     disable ngx_stream_upstream_hash_module
  --without-stream_upstream_least_conn_module
                                     disable ngx_stream_upstream_least_conn_module
  --without-stream_upstream_zone_module
                                     disable ngx_stream_upstream_zone_module
 
  --with-google_perftools_module     enable ngx_google_perftools_module  #内存管理模块合理调配系统内存资源给服务器
  --with-cpp_test_module             enable ngx_cpp_test_module    #启用ngx_cpp_test_module支持
 
  --add-module=PATH                  enable external module    #启用外部模块支持
  --add-dynamic-module=PATH          enable dynamic external module    #动态加载外部模块
 
  --with-cc=PATH                     set C compiler pathname    #用于C编译环境非默认的情况,指向C编译器路径
  --with-cpp=PATH                    set C preprocessor pathname    #指向C预处理路径
  --with-cc-opt=OPTIONS              set additional C compiler options    #设置C编译器参数
  --with-ld-opt=OPTIONS              set additional linker options    #设置连接文件参数
  --with-cpu-opt=CPU                 build for the specified CPU, valid values:    #指定编译的CPU
                                     pentium, pentiumpro, pentium3, pentium4,
                                     athlon, opteron, sparc32, sparc64, ppc64
 
  --without-pcre                     disable PCRE library usage
  --with-pcre                        force PCRE library usage        #url重写时所需模块,有更强大的正则引擎
 
  --with-openssl=DIR                 set path to OpenSSL library sources        #openssl所在位置
  --with-openssl-opt=OPTIONS         set additional build options for OpenSSL
 
  --with-debug                       enable debug logging

4、编译安装

注:由于nginx部分模块不支持动态加载,因此需要什么模块一定要提前指定好(有可能后期的版本也支持动态加载模块,像淘宝tengine分支已支持动态加载模块)。

  nginx-1.10.0]#./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --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 --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_flv_module --with-http_mp4_module --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi
  nginx-1.10.0]# make && make install
  nginx-1.10.0]# mkdir -pv /var/tmp/nginx/{client,proxy,fastcgi}

注:echo "export PATH=/usr/local/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh   #准备nginx程序执行是的环境变量

5、nginx.conf配置文件简要

nginx.conf配置文件路径:/etc/nginx/nginx.conf,同时/etc/nginx目录下还包含了fastcgi.conf,mime.types(mime类型配置文件),uwsgi_params(uwsgi配置文件段)。

nginx的配置文件分两大内容:

main控制nginx程序的运行

http主要是操作web服务器,http配置段下支持虚拟机包含在server段中,下面篇章说明

main主配置段:

user  nginx nginx;      #worker进程运行的属主与属组

worker_processes  3;    #worker进程数,建议少于CPU核心数

pid        /var/run/nginx/nginx.pid;    #指定pid文件位置

worker_rlimit_nofile 50000;             #显示所有worker进程所能打开的文件数目

worker_cpu_affinity 0001 0010 0100;     #绑定CPU,八核cpu就8个0,

events {

worker_connections  5000;          #每个worker进程所能并发处理的连接数

}

http配置段:

include       mime.types;       #包含mime配置文件所有配置内容

sendfile        on;             #开启sendfile功能

keepalive_timeout  65;          #开启长连接

server配置段:

listen       80;                #监听端口

server_name  localhost;         #服务器名字

location{}                      #针对匹配到不同的url可以下发不同的配置段(下方做说明)

gzip  on;                       #开启gzip压缩

6、Nginx做为http服务常见功能

注:以下的常见功能详细参考官网,http模块wiki文档以及应用实例

1)root path  #指定网页文件存放的路径

2)location [ = | ~ | ~* | ^~ ] uri { … }  #指定url,此处注意符合意义,内含url匹配优先级:[=] > [^~] > [~|~*] >不带任何修饰符,其中[~]表示区分大小写,[~*]表示不区分大小写

3)alias path #路径映射,注:访问资源URL与实际资源存储位置不一样,用别名定义实际存储位置

4)error_page #错误页面

5)ssl      #支持ssl

6)stu_status  #内置状态页面

7)url重写

8)定制日志

@@@@@@@@@@

1)、root path

********************************************************************************

如果root path 在location配置段中,如:

root /vhosts/web/; #注:绝对路径:优先级最高

location / {

root   /vhosts/web1;            #访问的是/vhosts/web1/index.html

index  index.html index.htm;

}

################################################################################

root /vhosts/web/;

location / {

root   html;                    #相对路径,访问的是/usr/local/nginx/html/index.html,

index  index.html index.htm;

}

********************************************************************************

********************************************************************************

如果root path在server配置段中,建议location不要配置root path,如下:

root /vhosts/web/;                  #此时才是访问/vhosts/web/index.html

location / {

index  index.html index.htm;

}

2)、location指定url,以下一小段测试配置文件为例说明:

location /documents/ {

root /vhosts/web1;

index  index.html index.htm;

}

location ^~ /images/ {

root /vhosts/web2;

index  index.html index.htm;

}

location ~* \.(png|jpg|jpeg)$ {

root /vhosts/web3;

index  index.html index.htm;

}

location = /aaa.png {

root /vhosts;

index  index.html index.htm;

}

在vhosts文件创建相应的文件夹和aaa.png图片

# tree

.

├── aaa.png

├── web1

│   ├── documents

│   │   └── aaa.png

│   └── images

│       └── aaa.png

├── web2

│   ├── documents

│   │   └── aaa.png

│   └── images

│       └── aaa.png

└── web3

├── documents

│   └── aaa.png

└── images

└── aaa.png

###访问:192.168.1.100/images/aaa.png

###分析:URL[/images/a.png],服务器匹配location事先定义好的url,可以匹配到第二个与第三个location,因为[^~] > [~*],所以得到/vhosts/web2/images/aaa.png

###访问:192.168.1.100/documents/aaa.png

###分析:URL[/documents/aaa.png],服务器匹配location事先定义好的url,可以匹配到第一个与第三个location,因为[~|~*] >不带任何修饰符,所以得到/vhosts/web3/documents/aaa.png

3)、alias path映射路径,以下一小段测试配置文件为例说明

location /documents/ {

alias /vhosts/web1/;

index  index.html index.htm;

}

###访问192.168.1.100/documents/,实际得到:/vhosts/web1/index.html

4)、error_page根据http响应状态码指定特定的错误页面,如以下

location / {

root /vhosts/web1/;

index  index.html index.htm;

}

error_page  404     /404.html;      #当访问不存在的资源时,回应404错误代码,重新指定/vhosts/web1/目录的404.html

5)、支持ssl,编译时需要添加模块 --with-http_ssl_module

ssl配置一般在server配置段中,如:

server {

listen       443 ssl;

server_name  localhost;

ssl_certificate      /usr/local/nginx/ssl/node1.whc.com.crt;    #从CA申请过来的证书

ssl_certificate_key  /usr/local/nginx/ssl/node1.key;            #私钥

ssl_session_cache    shared:SSL:1m;                             #ssl会话共享缓存,1分钟时间

ssl_session_timeout  5m;                                        #ssl会话超时时间5分钟

ssl_ciphers  HIGH:!aNULL:!MD5;

ssl_prefer_server_ciphers  on;

location / {

root /vhosts/web1;

index index.html index.htm;

}

}

注意:以上 node1.stu.com.crt证书和node1.key私钥,测试方便自行生成,方法如下:

@@@CA服务器生成私钥,自行签名

~]#cd /etc/pki/CA

CA]# touch index.txt

CA]# echo 01 > serial

CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048;)

CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3560

@@@客户端服务器生成私钥,并且生成证书申请请求,拷贝至ca服务器

~]# mkdir /usr/local/nginx/ssl

~]# cd /usr/local/nginx/ssl

ssl]# openssl genrsa -out node1.key 1024

ssl]# openssl req -new -key node1.key -out node1.csr -days 365

ssl]# scp node1.csr [email protected]:/tmp/node1.csr

@@@CA服务器对客户端传送过来的证书请求签发,重新拷贝回给node1客户端

CA]# openssl ca -in /tmp/node1.csr -out ./certs/node1.whc.com.crt -days 365

CA]# scp certs/node1.whc.com.crt [email protected]:/usr/local/nginx/ssl/

###测试访问https://node1.whc.com

6)、stu_status内置状态页面

在location中定义:

location /nginx-status {

allow 192.168.1.0/24;       #基于IP地址访问控制

deny all;

stub_status on;             #开启状态页面

access_log off;             #关闭状态页面的访问日志

}

###测试访问#curl http://node1.whc.com/nginx-status

Active connections: 4

server accepts handled requests

115 115 1542

Reading: 0 Writing: 2 Waiting: 2

以上各项参数含义如下:

Active connections:当前所有处于打开状态的连接数

accepts:已经接收进来的连接

handled:已经处理过的连接

requests:已经处理过的请求数

Reading:正处于接收请求状态的连接数

Writing:请求已经接收完成,正处于处理请求或发送响应过程的连接数

Waiting:保持连接且处理于活动状态的连接数

7)、url重写,将特定资源的URL路径修改重定向到其他路径,(break,last,redirect,permanent是可选参数)

location / {

root /vhosts/web1;

rewrite /documents/(.*\.png)$ /images/$1 break;     #将访问/vhosts/web1/documents/路径下以.png结尾的资源,全部重定向到/vhosts/web1/images/

index  index.html index.htm;

}

注:

break参数:如对rewrute规则重写后,由user agent对新的url重新发起新的请求,且不会在被location内的rewrite规则检查,

last参数:如对rewrute规则重写后,由user agent对新的url重新发起新的请求,如果还有被location内的rewrite匹配中那么就继续重写URL,要注意死循环

permanent参数:以301 #状态响应码(永久重定向),返回新的URL,

8)、定制日志

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;    #上面定义的日志在此处调用,定义日志信息的变量都是内置变量

三、Nginx常见操作命令

nginx -s 参数

nginx -s stop #快速的停止Nginx

nginx -s quit #优雅的停止Nginx

nginx -s reload #重载配置文件

service nginx start #启动Nginx

service nginx stop #停止Nginx

service nginx restart #重启Nginx

service nginxreload #重载配置

四、Nginx缓存服务器

环境说明:

测试服务器3台:192.168.1.100(node1.whc.com)Nginx缓存服务器,192.168.1.101(node2.whc.com)Nginx后端web服务器,192.168.1.10(本地物理机)客户机

2台服务器操作系统:centos 6.7

为避免其他因素影响测试:关闭防火墙,配置网络,配置本地主机,配置epel等

1、Nginx缓存服务器(node1.whc.com),创建缓存目录和修改hosts文件

# mkdir -pv /cache/nginx

# chown nginx:nginx /cache/nginx

# vim /etc/hosts

192.168.1.100    node1.whc.com

192.168.1.101    node1.whc.com

注:node2服务器,也要修改hosts文件

2、修改Nginx服务器(192.168.1.100)配置文件

# vim /etc/nginx/nginx.conf
user  nginx;
worker_processes  2;
 
error_log  /var/log/nginx/error.log error;
 
pid        /var/run/nginx/nginx.pid;
 
 
events {
    worker_connections  1024;
}
 
 
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
 
    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  /var/log/nginx/access.log  main;
 
    proxy_cache_path /cache/nginx/ levels=1:1 keys_zone=mycache:32m;    #缓存路径,1:1表示1级目录下有1个子目录,缓存key名称为mycache后面调用时要用,缓存大小为32m
 
    sendfile        on;
    #tcp_nopush     on;
 
    keepalive_timeout  65;
 
    gzip  on;
 
    upstream whc {        #定义一个负载均衡组whc
        server 192.168.1.101  weight=1 max_fails=2 fail_timeout=1;    #权重1,错误2次,每次超时1秒,就算健康状态,检测失败,还可以在后面街上backup定义其他web服务器,这里只定义一台够说明问题即可
       
        }
 
    server {
        listen       80;
        server_name  node1.whc.com;
 
        location / {
            root    /var/www/html;
            index    index.html index.htm;
            proxy_pass   http://whc/;    #将对本服务器首页的请求代理至负载均衡组whc,以实现负载均衡
            }
 
 
        location /index/ {
            proxy_cache mycache;    #调用缓存key为mycahe
            proxy_cache_valid 200 1m;    #返回值为200的缓存1分钟
           #root   /var/www/html;
            proxy_pass http://192.168.2.101/bbs.html;    #将url为/index/的代理至node2.whc.com/bbs.html
            proxy_set_header Host $host;        #把客户端真实主机名传递给后端服务器
            proxy_set_header X-Real-IP $remote_addr;    #把客户端真实ip传递给后端服务器
            index  index.html index.htm;
        }
 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/www/html;
        }
 
 
    }
 
}

###启动服务

# service nginx reload

# service nginx restart

2、后端nginx,修改nginx.conf,并且安装nginx需要添加--with-http_realip_module模块

#vim /etc/nginx/nginx.conf,添加开启如下配置:

set_real_ip_from   192.168.1.0/24;     #这里是前端代理服务器ip,可以是单个IP或者IP段

real_ip_header     X-Real-IP;

3、查看缓存结果

# cd /cache/nginx

# ls

3

# ls 3/c/dsddsfadarea2432wfea234ac22910c12ad5

@@@@@@@下一章将介绍Nginx之二:负载均衡及高可用@@@@@@@

时间: 2024-08-24 17:01:38

Nginx之一:编译安装及基础应用的相关文章

nginx的编译安装 centos7

nginx的编译安装 yum install -y vim lrzsz tree screen psmisc lsof tcpdump wget ntpdate gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools iotop bc zip unzip zlib-devel bash-completion nfs-utils automake libxml2 libx

Nginx的编译安装

Nginx的编译安装 一.Nginx的特点 1.Nginx 专为性能优化而开发,性能是其最重要的考量,实现上非常注重效率 .它支持内核 Poll 模型,能经受高负载的考验,有报告表明能支持高达 50,000 个并发连接数. 2.Nginx 具有很高的稳定性,Nginx 采取了分阶段资源分配技术,使得它的 CPU 与内存占用率非常低. 3.Nginx 代码质量非常高,代码很规范,手法成熟,模块扩展也很容易. 4.Nginx 还可以实现无缓存的反向代理加速,简单的负载均衡和容错. 二.获取并编译Ng

Nginx 的编译安装和URL地址重写

本文转自:http://www.178linux.com/14119#rd?sukey=ecafc0a7cc4a741b573a095a3eb78af6b4c9116b74d0bbc9844d8fc5e8b50b3fc807541ae53fd06c67ac4f4adaae6981 在此只是做个笔记给自己看的. Nginx专题: 从编译安装到URL重写 前言 环境介绍 Nginx介绍 编译安装Nginx 配置文件解释 main和event{}的配置 http{}的基本配置 配置Nginx 搭建一个

Nginx的编译安装及基本使用

环境说明:Centos6.6_64.Vmware11和nginx-1.8.0 一.nginx说明 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,第一个公开版本0.1.0发布于2004年10月4日.其将源代码以类BSD许可证的形式发布,因它的稳定性.丰富的功能集.示例配置文件和低系统资源的消耗而闻名

20190314 Nginx:编译安装、Location的使用、常用变量

Nginx是一个高性能的HTTP和反向代理服务.是一款轻量级的Web服务器和反向代理服务器及电子邮件代理服务器,特点:占有内存少,并发能力强, epoll:在Linux 2.6内核中提出的select和poll的增强版本支持水平触发LT和边缘触发ET,最大的特点在于边缘触发,它只告诉进程哪些fd刚刚变为就需态,并且只会通知一次使用"事件"的就绪通知方式,通过epoll_ctl注册fd,一旦该fd就绪,内核就会采用类似callback的回调机制来激活该fd,epoll_wait便可以收到

CentOS 6.5 Nginx 的编译安装、以及让nginx 支持 SSI 相对路径写法

1. nginx 下载 进入 http://nginx.org/en/download.html 下载,我是选择的 "Stable version" 稳定版本的下载 # wget http://nginx.org/download/nginx-1.6.2.tar.gz 2. 解压编译安装 # tar -zxvf nginx-1.6.2.tar.gz # cd nginx-1.6.2 安装一些nginx用到的依赖软件,如果不开启ssl可以不用安装openssl,回头用到时可以返回这里重新

LNMP—Nginx的编译安装

Nginx的官方下载地址http://nginx.org 进入目录 [[email protected] ~]# cd /usr/local/src 下载Nginx [[email protected] src]# wget http://nginx.org/download/nginx-1.6.3.tar.gz 解压Nginx [[email protected] src]# tar zxvf nginx-1.6.3.tar.gz 编译安装 [[email protected] src]# c

Nginx的编译安装及服务启动脚本

1.解决依赖关系 编译安装nginx需要事先需要安装开发包组"Development Tools"和 "Development Libraries".同时,还需要专门安装pcre-devel包:# yum -y install pcre-devel 2.添加系统用户,实现与之运行nginx的服务进程 groupadd -r nginx useradd -r -g nginx nginx id nginx    查看新建的用户id 3.下载源码包上传编译安装 (www

nginx软件编译安装

第一个里程:软件依赖包安装pcre-devel: perl语言正则表达式兼容软件包openssl-devel:使系统支持https方式访问yum install -y pcre-devel openssl-devel 第二个里程:创建一个管理nginx进程的虚拟用户 useradd www -s /sbin/nologin/ -M 第三个里程:下载并解压nginx软件cd /server/toolswget http://nginx.org/download/nginx-1.12.2.tar.g