Nginx及其相关配置详解(二)

与套接字相关的配置:

1、server { … }  #配置一个虚拟主机;

        Default:—

        Context:http

server {   # 配置虚拟主机示例
    listen address[:PORT]|PORT;
    server_name SERVER_NAME;
    root /PATH/TO/DOCUMENT_ROOT;
}

===========================================================================

2、listen PORT|address[:port]|unix:/PATH/TO/SOCKET_FILE  #定义虚拟主机所监听的端口

        listen address[:port] [default_server] [ssl] [http2 | spdy]  [backlog=number] [rcvbuf=size] [sndbuf=size]

        Default:listen *:80 | *:8000;

        Context:server

default_server:设定为默认虚拟主机;

ssl:限制仅能够通过ssl连接提供服务;

backlog=number:后援队列长度;

rcvbuf=size:接收缓冲区大小;

sndbuf=size:发送缓冲区大小

 ===========================================================================

3、server_name name …;  #指明虚拟主机的主机名称;后可跟多个由空白字符分隔的字符串;

        Default:server_name “”;

        Context:server

指明虚拟主机的主机名称;后可跟多个由空白字符分隔的字符串;

支持*通配任意长度的任意字符;server_name *.rookie.com  www.rookie.*

支持~起始的字符做正则表达式模式匹配;server_name ~^www\d+\.rookie\.com$

匹配机制:

  (1) 首先是字符串精确匹配

  (2) 左侧*通配符

  (3) 右侧*通配符            

(4) 正则表达式

 ===========================================================================

4、tcp_nodelay on | off;  #在keepalived模式下的连接是否启用TCP_NODELAY选项;将多个小包打包成一个报文发送给客户端

tcp_nopush on|off;

在sendfile模式下,是否启用TCP_CORK选项

        Default:tcp_nodelay on;

        Context:http, server, location

 ===========================================================================

5、sendfile on | off;  #是否启用sendfile功能;      

        Default:sendfile off;

        Context:http, server, location, if in location

 ===========================================================================

定义路径相关的配置:

6、root path;   #设置web资源路径映射;用于指明用户请求的url所对应的本地文件系统上的文档所在目录路径;可用的位置:http, server, location, if in location

        Default:root html;

        Context:http, server, location, if in location

 ===========================================================================

7、location [ = | ~ | ~* | ^~ ] uri { … }  #在一个server中location配置段可存在多个,用于实现从uri到文件系统的路径映射;ngnix会根据用户请求的URI来检查定义的所有location,并找出一个最佳匹配,而后应用其配置

location @name { … }

        Default:—

        Context:server, location

=:对URI做精确匹配;例如, http://www.rookie.com/, http://www.rookie.com/index.html

            location = / {

                …

            }

~:对URI做正则表达式模式匹配,区分字符大小写

 ~*:对URI做正则表达式模式匹配,不区分字符大小写

^~:对URI的左半部分做匹配检查,不区分字符大小写

不带符号:匹配起始于此uri的所有的url

匹配优先级:=, ^~, ~/~*,不带符号

===========================================================================

8、alias path;   #定义路径别名,文档映射的另一种机制;仅能用于location上下文

        Syntax: alias path;

        Default:—

        Context:location

注意:location中使用root指令和alias指令的意义不同

(a) root,给定的路径对应于location中的/uri/左侧的/

(b) alias,给定的路径对应于location中的/uri/右侧的/

/下除禁止172.16.252.245访问外,其它都允许

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        location / {
                deny 172.16.250.217;/      #下除禁止172.16.252.245访问
                allow all;                           #其它都允许
        }
}
[root@nginx2 ~]#vim /etc/hosts           #做域名解析
172.16.254.217  www.ilinux.io
[root@nginx2 ~]#curl http://www.ilinux.io
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.10.2</center>
</body>
</html>

===========================================================================

禁止172.16.252.245访问所有jpg|png结尾格式的图片

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        location ~* \.(jpg|png)$ {
                deny 172.16.250.217;    #禁止172.16.252.245访问所有jpg|png结尾格式的图片
                allow all;                        #其余的都允许访问
        }
}
[root@nginx2 ~]#curl http://www.ilinux.io    # 因为不是访问jpg|png结尾格式的图片,所以能显示内容
<h1>Nginx Vhost1</h1>
[root@nginx1 /data/nginx/vhost1]#find /usr/share/ -iname "*.jpg" -exec cp {} ./ \;  # 拷贝图片到当前路径下

Nginx及其相关配置详解(二) 

[root@nginx2 ~]#curl http://www.ilinux.io/leaf.jpg     
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/1.10.2</center>
</body>
</html>

===========================================================================

相对location之外的,location中定义的生效

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        location / {
                root /data/nginx/vhost2;     #相对于root /data/nginx/vhost1;在location中定义的生效,如不定义root,则继承root /data/nginx/vhost1;
                allow all;
        }
        location ~* \.(jpg|png)$ {
                deny 172.16.250.217;
                allow all;
        }
}
[root@nginx2 ~]#curl http://www.ilinux.io/index.html
<h1>vhost2</h1>

===========================================================================

[root@nginx1 /data/nginx/vhost1]#mkdir images
[root@nginx1 /data/nginx/vhost1]#mv 2560x1600.jpg astronaut.jpg background.jpg images/
[root@nginx1 /data/nginx/vhost1]#nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@nginx1 /data/nginx/vhost1]#nginx -s reload

Nginx及其相关配置详解(二) 

===========================================================================

[root@nginx1 /data/nginx/vhost1]#mkdir /data/pictures/
[root@nginx1 /data/nginx/vhost1]#cp cat-eye.jpg day.jpg energy-arc.jpg /data/pictures/
[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        location / {
                #root /data/nginx/vhost2;
                allow all;
        }
        location ~* \.(jpg|png)$ {
                deny 172.16.250.217;
                allow all;
        }
        location /images/ {
                root /data/pictures/;相当于在/下找images
        }
}
[root@nginx1 /data/nginx/vhost1]#nginx -t
[root@nginx1 /data/nginx/vhost1]#nginx -s reload

Nginx及其相关配置详解(二) 

[root@nginx1 /data/nginx/vhost1]#mkdir /data/pictures
[root@nginx1 /data/nginx/vhost1]#cp cat-eye.jpg day.jpg energy-arc.jpg /data/pictures/
[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        location / {
                #root /data/nginx/vhost2;
                allow all;
        }
        location ~* \.(jpg|png)$ {
                deny 172.16.250.217;
                allow all;
        }
        location ^~/images/ {
                root /data/pictures/;
        }
}
[root@nginx1 /data/nginx/vhost1]#nginx -t
[root@nginx1 /data/nginx/vhost1]#nginx -s reload

Nginx及其相关配置详解(二) 

===========================================================================

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        location / {
                #root /data/nginx/vhost2;
                allow all;
        }
        location ~* \.(jpg|png)$ {
                deny 172.16.250.217;
                allow all;
        }
        location ^~/images/ {
                alias /data/pictures/;
        }
}

Nginx及其相关配置详解(二) 

Nginx及其相关配置详解(二)

===========================================================================

9、index file …;   #默认主页面定义

        Default:index index.html;

        Context:http, server, location

 ===========================================================================

10、error_page code … [=[response]] uri;  #定义默认错误页面

        Default:—

        Context:http, server, location, if in location

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf 
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        location / {
                #root /data/nginx/vhost2;
                allow all;
        }
        location ~* \.(jpg|png)$ {
                deny 172.16.250.217;
                allow all;
        }
        location ^~/images/ {
                alias /data/pictures/;
        }
        error_page 404 /notfound.html;         #如果是404就在notfound.html中
        location = /notfound.html {               #如果访问notfound.html
                root /data/nginx/error_pages;    #错误页面就在/data/nginx/error_pages/notfound.html中
        }
}
[root@nginx1 /etc/nginx/conf.d]#mkdir /data/nginx/error_pages
[root@nginx1 /etc/nginx/conf.d]#vim /data/nginx/error_pages/notfound.html
<h2>--------------------</h2>
<h3>notfound</h3>
[root@nginx1 /etc/nginx/conf.d]#nginx -s reload

Nginx及其相关配置详解(二)

 ===========================================================================

11、try_files file … uri;

 ===========================================================================

定义客户端请求的相关配置:

12、keepalive_timeout timeout [header_timeout];  #设定保持连接的超时时长,0表示禁止长连接;默认为75s

        Default:keepalive_timeout 75s;

        Context:http, server, location

 ===========================================================================

13、keepalive_requests number;  #在一次长连接上所允许请求的资源的最大数量,默认为100(使用默认值即可)

        Default:keepalive_requests 100;

        Context:http, server, location

 ===========================================================================

14、keepalive_disable none | browser …;  #对哪种浏览器禁用长连接

        Default:keepalive_disable msie6;

        Context:http, server, location

 ===========================================================================

15、send_timeout time;  #向客户端发送响应报文的超时时长,是指两次写操作之间的间隔时长

如客户端发送请求后,由于断电等等原因,无法接收到服务器发送的报文

        Default:send_timeout 60s;

        Context:http, server, location

===========================================================================

16、client_body_buffer_size size;  #用于接收客户端请求报文的body部分的缓冲区大小;默认为16k;超出此大小时,其将被暂存到磁盘上的由client_body_temp_path指令所定义的位置

        Default:client_body_buffer_size 8k|16k;

        Context:http, server, location

 ===========================================================================

17、client_body_temp_path path [level1 [level2 [level3]]];  #设定用于存储客户端请求报文的body部分的临时存储路径及子目录结构和数量

        Default:client_body_temp_path client_body_temp;

        Context:http, server, location

16进制的数字

client_body_temp_path  /var/tmp/client_body  2 1 1     

2表示256个一级子目录(256)    1表示每个一级子目录下有16个二级子目录(256*16)    1表示每个二级子目录下有16个三级子目录(16*256*16)

1:表示用一位16进制数字表示一级子目录;0-f

2:表示用2位16进程数字表示二级子目录:00-ff

2:表示用2位16进程数字表示三级子目录:00-ff

 ===========================================================================

对客户端进行限制的相关配置:

18、limit_rate rate;  #限制响应给客户端的传输速率,单位是bytes/second,0表示无限制

        Default:limit_rate 0;

        Context:http, server, location, if in location

 ===========================================================================

19、limit_except method … { … }  #限制对指定的请求方法之外的其它方法的使用客户端

        Default:—

        Context:location

 

        limit_except GET {               #GET以外的方法

            allow 192.168.1.0/32;      #只允许192.168.1.0/32网段使用

            deny  all;

        }       

 ===========================================================================

20、aio on | off | threads[=pool];  #是否启用aio功能(使用on)        

        Default:aio off;

        Context:http, server, location

 ===========================================================================

21、directio size | off;  #在Linux主机启用O_DIRECT标记,此处意味文件大于等于给定的大小时使用,例如directio 4m

        Default:directio off;

        Context:http, server, location

 ===========================================================================

22、open_file_cache off;  # 是否开启缓存

        open_file_cache max=N [inactive=time];

        Default:open_file_cache off;

        Context:http, server, location

nginx可以缓存以下三种信息

(1) 文件的描述符、文件大小和最近一次的修改时间

(2) 打开的目录结构

(3) 没有找到的或者没有权限访问的文件的相关信息

max=N:可缓存的缓存项上限;达到上限后会使用LRU(最近最少使用)算法实现缓存管理

inactive=time:缓存项的非活动时长,在此处指定的时长内未被命中的或命中的次数少于open_file_cache_min_users指令所指定的次数的缓存项即为非活动项

 ===========================================================================

23、open_file_cache_valid time;  #缓存项有效性的检查频率;默认为60s(空间不够用可将秒数调低)

        Default:open_file_cache_valid 60s;

        Context:http, server, location

 ===========================================================================

24、open_file_cache_min_uses number;  #在open_file_cache指令的inactive参数指定的时长内,至少应该被命中多少次方可被归类为活动项

        Default:open_file_cache_min_uses 1;

        Context:http, server, location

 ===========================================================================

25、open_file_cache_errors on | off;  #是否缓存查找时发生错误的文件一类的信息(使用on)

        Default:open_file_cache_errors off;

        Context:http, server, location

 ===========================================================================

ngx_http_access_module模块:

实现基于ip的访问控制功能

26、allow address | CIDR | unix: | all;(允许)

===========================================================================

27、deny address | CIDR | unix: | all;(禁止)

http, server, location, limit_except

===========================================================================

ngx_http_auth_basic_module模块

实现基于用户的访问控制,使用basic机制进行用户认证;

28、auth_basic string | off;

 ===========================================================================

29、auth_basic_user_file file;

location /admin/ {

     alias /webapps/app1/data/;

     auth_basic “Admin Area”;

     auth_basic_user_file /etc/nginx/.ngxpasswd;

}

注意:htpasswd命令由httpd-tools所提供

[root@nginx1 /etc/nginx/conf.d]#yum install httpd-tools
[root@nginx1 /etc/nginx/conf.d]#htpasswd -c -m /etc/nginx/.ngxpasswd tom
[root@nginx1 /etc/nginx/conf.d]#htpasswd -m /etc/nginx/.ngxpasswd jerry
[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
location ~* ^/(admin|login) {       #如果路径以admin|login开头,
                auth_basic "admin area or login url";    
                auth_basic_user_file /etc/nginx/.ngxpasswd;    #文件路径/etc/nginx/.ngxpasswd
}
[root@nginx1 /etc/nginx/conf.d]#mkdir /data/nginx/vhost1/admin
[root@nginx1 /etc/nginx/conf.d]#vim /data/nginx/vhost1/admin/index.html
<h1>admin area</h1>

Nginx及其相关配置详解(二) 

输入用户名和密码后成功进入

Nginx及其相关配置详解(二)

 ===========================================================================

ngx_http_stub_status_module模块(nginx内置的内建状态页

用于输出nginx的基本状态信息;

Active connections: 291

server accepts handled requests

16630948 16630948 31070465

Reading: 6 Writing: 179 Waiting: 106

Active connections: 活动状态的连接数;

accepts:已经接受的客户端请求的总数;

handled:已经处理完成的客户端请求的总数;

requests:客户端发来的总的请求数;

Reading:处于读取客户端请求报文首部的连接的连接数;

Writing:处于向客户端发送响应报文过程中的连接数;

Waiting:处于等待客户端发出请求的空闲连接数;

30、stub_status;

Default:—         

Context:server, location

配置示例:
location  /basic_status {
stub_status;
}

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
location /ngxstatus {
                stub_status;
                 access_log off;日志不记录
}
[root@nginx1 /etc/nginx/conf.d]#nginx -t
[root@nginx1 /etc/nginx/conf.d]#nginx -s reload

Nginx及其相关配置详解(二)

===========================================================================

ngx_http_log_module模块

he ngx_http_log_module module writes request logs in the specified format.(ngx_http_log_module模块写入请求登录指定的格式)

31、log_format name string …;   #日志格式

        Default:log_format combined “…”;

        Context:http

string可以使用nginx核心模块及其它模块内嵌的变量;

        $bytes_sent:发送到客户端的字节数

        $connection:连接序列号

        $connection_requests:目前一些通过连接发出的请求(1.1.18)

        $msec:时间与一个毫秒分辨率秒日志写入的时间

        $pipe:”p”如果请求被流水线

        $request_length:请求长度

        $request_time:请求处理时间在毫秒分辨率秒; 第一字节之间经过的时间是从在客户端和日志写入读出之后,最后的字节被发送到客户端

        $status:响应状态

        $time_iso8601:在ISO 8601标准格式的本地时间

        $time_local:在通用日志格式的本地时间

 ===========================================================================

32、access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];   #访问日志文件路径,格式及相关的缓冲的配置;

        access_log off;

        Default:access_log logs/access.log combined;

        Context:http, server, location, if in location, limit_except

访问日志文件路径,格式及相关的缓冲的配置;

            buffer=size

            flush=time

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        listen 80;
        server_name www.ilinux.io;
        root /data/nginx/vhost1;
        access_log /var/log/nginx/vhost1_access.log main; 定义在server中,对整个文件有效
[root@nginx1 /etc/nginx/conf.d]#nginx -s reload
[root@nginx1 /etc/nginx/conf.d]#tail /var/log/nginx/vhost1_access.log   查看日志
172.16.254.217 - tom [14/Jul/2017:22:02:12 +0800] "GET /images/fish.jpg HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.16.254.217 - tom [14/Jul/2017:22:04:33 +0800] "GET /images/2560x1600.jpg HTTP/1.1" 404 48 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.16.254.217 - tom [14/Jul/2017:22:05:29 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"
172.16.254.217 - tom [14/Jul/2017:22:05:43 +0800] "GET /admin/ HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0" "-"

对于某个location使用单独的访问日志,以admin为例

location ~* ^/(admin|login) {
                auth_basic "admin area or login url";
                auth_basic_user_file /etc/nginx/.ngxpasswd;
                access_log /var /log/nginx/vhost1_access.log main;
}

 ===========================================================================

33、open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];    #缓存各日志文件相关的元数据信息;

        open_log_file_cache off;

        Default:open_log_file_cache off;

        Context:http, server, location

缓存各日志文件相关的元数据信息;

            max:缓存的最大文件描述符数量;

            min_users:在inactive指定的时长内访问大于等于此值方可被当作活动项;

            inactive:非活动时长;

            valid:验正缓存中各缓存项是否为活动项的时间间隔;

 ===========================================================================

ngx_http_gzip_module:

The ngx_http_gzip_module module is a filter that compresses responses using the “gzip” method. This often helps to reduce the size of transmitted data by half or even more.(ngx_http_gzip_module模块是一个过滤器,压缩响应使用“gzip”方法。这通常有助于将传输数据的大小减少一半甚至更多。)

1、gzip on | off;

Default: gzip off;

Context: http, server, location, if in location

Enables or disables gzipping of responses.(启用或禁用Gzipping反应)

是否启用gzip压缩响应报文;不是所有浏览器都支持压缩机制 

===========================================================================

2、gzip_comp_level level;

Default: gzip_comp_level 1;

Context: http, server, location

Sets a gzip compression level of a response. Acceptable values are in the range from 1 to 9.(设置一个响应的gzip压缩级别。可接受的值在1到9之间。默认为1,数压越大压缩比越大)

=========================================================================== 

3、gzip_disable regex …;

Default: —

Context: http, server, location

Disables gzipping of responses for requests with “User-Agent” header fields matching any of the specified regular expressions.(禁用Gzipping响应“用户代理标头字段匹配任何指定的正则表达式的要求)

regex是匹配客户端浏览器类型的模式,表示对所有匹配到的浏览器不执行压缩响应;因为有些浏览器类型不支持压缩

 ===========================================================================

4、gzip_min_length length;

Default: gzip_min_length 20;

Context: http, server, location

启用压缩功能的响应报文大小阈值

 ===========================================================================

5、gzip_buffers number size;

Default: gzip_buffers 32 4k|16 8k;

Context: http, server, location

支持实现压缩功能时为其配置的缓冲区数量及每个缓存区的大小

 ===========================================================================

6、gzip_proxied off | expired | no-cache | no-store | private | no_last_modified | no_etag | auth | any …;

Default: gzip_proxied off;

Context: http, server, location

nginx作为代理服务器接收到从被代理服务器发送的响应报文后,在何种条件下启用压缩功能的

off:对代理的请求不启用

expired:如果响应报文首部包含expired字段并有值,其值即是有效的但过期了,因为禁用了缓存机制,则启用压缩

no-cache, no-store,private:表示从被代理服务器收到的响应报文首部的Cache-Control的值为此三者中任何一个,则启用压缩功能

=========================================================================== 

7、gzip_types mime-type …;

Default: gzip_types text/html;

Context: http, server, location

压缩过滤器,仅对此处设定的MIME类型的内容启用压缩功能;默认为text/html

示例:

gzip  on;

gzip_comp_level 6;

gzip_min_length 64;

gzip_proxied any;

gzip_types text/xml text/css  application/javascript

例:

[root@nginx1 /etc/nginx]#vim nginx.conf
gzip on;
gzip_comp_level 6;  #压缩级别为6
gzip_types text/css  text/xml  application/javascript   #对text/css  text/xml  application/javascript这三种进行压缩
[root@nginx1 /etc/nginx]#vim nginx.conf
gzip on;
gzip_comp_level 6;  #压缩级别为6
gzip_types text/html text/css text/xml application/javascript   #对text/html text/css text/xml application/javascript这四种进行压缩
[root@nginx1 /etc/nginx]#nginx -s reload
[root@nginx1 /etc/nginx]#cp nginx.conf /data/nginx/vhost1/nginx.html

 Nginx及其相关配置详解(二)

 ===========================================================================

ngx_http_ssl_module模块:

ssl协议位于传输层和应用层之间的半层;应用层协议在开发时调用ssl功能,就能支持ssl,有些应用层协议在调用ssl时,可把ssl当做一个模块,用到时就可以调用;就像httpd,可提供http服务,也可提供https服务;只不过,如果是基于rpm安装方式时,需要安装mod_ssl模块;

ssl协议是基于tcp通信的,经过tcp3次握手后,才能进行sslhandshake;

服务器发证书给客户端,包括支持哪些加密算法,与客户端协商;客户端接收后证书后,要验证证书持有者与访问主机站点地址是否一致,证书的颁发机构是否是信任的机构,验证证书的有效期,用CA公钥解密数字签名,用同样的算法加密特征码,对比是否一致,验证CA的合法性;还要检查证书吊销列表;验证通过后,才通信;但通信时,还要有密钥交换的过程,用对方的公钥加密选择的一次性对称密钥,然后传递给对方,对方用私钥解密后,就得出了密码,然后就用这个密码来加密客户端请求的资源之后,将资源发送给客户端,随后就是ssl双方之间的通信;

这个通信是基于ssl会话进行的,所有http报文在发送给tcp层之前,先交给ssl层,ssl层会把文本形式的报文,转换为ssl报文,ssl报文是为二进制格式的;随后才交给tcp层;因此基于ssl层的会话,可认为是在整个报文多了一层,即数据之外是应用层,应用层之外是ssl会话层,然后才是tcp层,最后经过封装MAC发送;

运营商能截获客户端的访问页面,插入相关的链接或广告,站点有可能都不知道;在cdn层次上分析客户的访问;因此,站点现在都做全站https,这样,再运营商插入广告,客户就打不开网页,从而,运营商为了满足客户端打开网页的需求,就不能插入广告了;

ssl会话是基于tcp隧道承载的一种协议,是在tcp建立连接之后,才建立的;而在拆除会话时,是先拆除ssl会话,再拆除tcp连接;

ssl加解密会给cpu带来很大压力;将来做服务器时,要做选型;软硬件模型多服务器做压测,要满足业务需要;客户端使用域名访问服务器站点,通过DNS服务器解析返回一个请求的要访问服务器ip地址,之后,客户端就封装http请求报文,http报文基于get方法,body部分一般是空的,再外面封装的是http请求报文首部,当中有大多请求报文的header,其中有一个header叫做host,这个host给的就是在浏览器中键入的主机名;再封装tcp等等;域名只在http请求报文首部才用到,而首部是在ssl会话内部的;所以两台主机间通信tcp会话是基于ip地址进行,ssl会话也是基于ip地址进行的;双方身份识别是基于ip地址,而没有用到主机名;所以,任何一台服务器只有一个IP地址的主机,只能提供一个https的虚拟主机;但现在有个开源项目,能够实现单台主机使用多个https的虚拟主机

灰度模型:服务器上线、下线一批一批来打补丁

1、ssl on | off;

Default: ssl off;

Context: http, server

Enables the HTTPS protocol for the given virtual server.(启用给定虚拟服务器的HTTPS协议。)

是否启用当前虚拟主机的ssl

手动测试时,可临时关闭

基于ip地址的ssl会话,在一个ip上进行只能一个虚拟主机ssl会话

===========================================================================

2、ssl_certificate file;

Default: —

Context: http, server

当前虚拟主机使用PEM格式的证书文件

=========================================================================== 

3、ssl_certificate_key file;

Default: —

Context: http, server

指明私钥文件;当前虚拟主机使用的证书文件中的公钥配对儿的私钥文件路径,PEM格式

 ===========================================================================

4、ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2];

Default: ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

Context: http, server

支持ssl协议版本,默认为后三个;最好使用TLSv1以上的版本

 ===========================================================================

5、ssl_session_cache off | none | [builtin[:size]] [shared:name:size];

Default: ssl_session_cache none;

Context: http, server

builtin[:size]:使用OpenSSL内建的缓存,此缓存为每worker进程私有;

[shared:name:size]:在各worker之间使用一个共享的缓存;

ssl会话创建非常消耗资源,能缓存下来对同一主机的多次请求,在有效时间内可不用建立ssl会话,基于缓存来实现;指明ssl会话的缓存机制;

off:禁止使用会话;坚决禁止;

none:禁止使用会话;温和禁止;告诉客户端会话有可能被重用,但并不保证;

builtin:使用openssl(加密的库)内建的缓存机制,此为各worker独占;

为每个worker进程在自己的空间中加载ssl相关库,各worker是不共享的;每个worker自己独立管理自己的ssl会话缓存;

缺陷:同一个用户请求,第一个请求调度在第一个worker响应,第二个请求有可能被调度到第二个worker响应,这样缓存有可能无法被命中;

shared:相对于builtin而言,ssl缓存是由各worker共享的缓存;缓存空间需要定义name,size等,每个共享必须有名字;共享的缓存由nginx进程所管理的一段内存空间,对于nginx,共享内存空间非常多,所以共享内存空间要有名字和空间大小;

name:缓存空间的名称;每一段空间间必须有一个名字;

size:字节为单位的缓存空间的大小,每1MB内存空间可缓存4000个会话;10M空间就可缓存4万个会话;一般只使用共享,效率会高些;多个虚拟主机可使用同一段缓存空间来缓存自己的ssl会话

===========================================================================

6、ssl_session_timeout time;

Default: ssl_session_timeout 5m;

Context: http, server

客户端一侧的连接可以复用ssl session cache中缓存的ssl参数的有效时长;ssl会话超时时长,默认是5分钟

配置示例:

server {

     listen 443 ssl;     ————————-强制ssl会话

     server_name localhost; ——————虚拟主机名

     ssl_certificate cert.pem; —————–证书

     ssl_certificate_key cert.key;————-私钥

     ssl_session_cache shared:SSL:1m; —-共享ssh缓存大小

     ssl_session_timeout 5m; —————–会话ssl的超时时长

     ssl_ciphers HIGH:!aNULL:!MD5; ——–ssl的加密算法

     ssl_prefer_server_ciphers on; ———–倾向于使用服务器端的加密算法

     location / {

     root html;

     index index.html index.htm;

}

===========================================================================

ngx_http_rewrite_module模块:

The ngx_http_rewrite_module module is used to change request URI using PCRE regular expressions, return redirects, and conditionally select configurations.(ngx_http_rewrite_module模块使用PCRE正则表达式,变更请求URI返回重定向,并有条件地选择配置。)

用于实现将用户请求的URI基于正则式转换为其它URl机制;并且以重定向方式默认返回给客户端,让客户端对新的URI重新再次发起请求

处理步骤:

在server当中,使用rewrite指令定义的重写机制是自上而下逐条进行处理的,类似于iptables的规则都是自上而下应用设置的;如果被第一条处理,下面不会再检查;因为处理过了已经返回给客户端,客户端已经再次请求新URI了。

将用户请求的URI基于regex所描述的模式进行检查,而后完成替换

执行过程会重复如下操作:

(1)基于用户请求的URI去搜索location;

(2)在一个location内部的指令,是从上而下逐条检查;

(3)如果URI被重写循环重复,最多10次,就会提示错误页面

(4)用户请求到达nginx服务器端时,服务端有多个server虚拟主机,映射到哪个server,取决于用户请求的server name,根据用户请求的server name最终被判断到底请求的是哪个server,从而判断属于哪个server,每个srever内部还有多个location,每个location用来定义URL到本地文件系统路径的映射方式以及内部处理机制;因此,还有根据用户请求的URL去匹配location;所以,这里有2步操作:

第一步,根据server name匹配是哪个server,

第二步,根据用户请求的URL去匹配server内部的location;在一个location内部可能存在多个rewrite指令,rewrite指令作用就是把用户请求的URL换成其它的URL;

例如:用户请求的是http://server2/hello.htm,被匹配到第二个srever上,其中location中如果第一条rewrite指令,指明了把hello.html指向了hi.html;则返回给客户端去请求http://server2/hi.html,而后客户端要重新再次发请求,依然自上而下去匹配属于哪个server、哪个location;如果hi.html被第三location匹配则被location中的指令处理

例:循环重写示例:

rewrite  (.*)\.jpg$ –> $1.html;

rewrite  (.*)\.html$ –> $1.jpg;  

写的规则次序很重要:根据用户请求的主机名来判断是哪个server;确定server后,根据location完成搜索,根据location中的重写规则完成重写,重写后,返回客户端一个新的URL,客户端再次发请求;如果中间出现循环最大循环10此;URL重写可实现跨server,例如请求http://server2/images/1.jpg,改写为http://images/$1.html,这个images可能是其它虚拟主机,甚至还可能是另一台物理服务器;

所有URL重写,可在一个主机上的一个server内只把URL部分重写,但有时可以把server重写,实现镜像服务器;把里面的服务器地址改了,但是URL没改;

URL重写可把对应动态资源的请求转换为静态的URL地址;因此,这个结果可被搜索引擎收录,还可被缓存服务器缓存;可理解为把动态资源静态化的效果;

如果用户访问的php动态资源,很多时候缓存服务器是不缓存这个结果的,但是如果动态资源生成的结果不会再变化可以缓存服务器缓存下来时(静态的存下来),可以给静态URL;这种机制可在nginx的rewrite功能来实现;但用到正则式就要启动正则表达式引擎,这样会消耗更多资源;因此,尽量不使用

1、rewrite regex replacement [flag]

将用户请求的URI基于regex所描述的模式进行检查,匹配到时将其替换为replacement指定的新的URI;

注意:如果在同一级配置块中存在多个rewrite规则,那么会自下而下逐个检查;被某条件规则替换完成后,会重新一轮的替换检查,因此,隐含有循环机制;[flag]所表示的标志位用于控制此循环机制;

如果replacement是以http://或https://开头,则替换结果会直接以重向返回给客户端;

301:永久重定向;

[flag]:

last:重写完成后停止对当前URI在当前location中后续的其它重写操作,而后对新的URI启动新一轮重写检查;提前重启新一轮循环;

break:重写完成后停止对当前URI在当前location中后续的其它重写操作,而后直接跳转至重写规则配置块之后的其它配置;结束循环;

redirect:重写完成后以临时重定向方式直接返回重写后生成的新URI给客户端,由客户端重新发起请求;不能以http://或https://开头;

permanent:重写完成后以永久重定向方式直接返回重写后生成的新URI给客户端,由客户端重新发起请求;

如果第一条规则被last匹配了,意味着新的URI会重新做一次请求,nginx会在内部自动重新检查,如果又被这个location匹配,还会再检查一遍;最终将资源加载后返回给客户端;

如果第一条规则被break匹配,rewrite停止在第一条中的新URI上,意味着不再被执行重写指令即跳出循环,nginx会在内部而继续执行此location内的其它指令;最终将资源加载后返回给客户端;

如果第一条规则被redirect匹配,直接将新URL返回给客户端,浏览器自动对新URL发请求,这个新URL有可能还是本机中location,再解析匹配检查,所以,redirect直接返回的不是资源,而是一个新的URL;

但redirect和permanent,表示当用户请求的URL被重定向时,直接返回用户新的URL,让用户自己重新请求,只不过这两者的区别为,redirect是临时重定向,permanent是永久重定向;

注意:last和break都是nginx自动的在内部进行后续处理;

  redirect和permanent是nginx返回URL给客户端浏览器自动重新请求的

注意:

(1)在同一location中存在多个rewrite规则会自上而下逐个被检查(隐含循环);可使用flag控制此循环功能;

(2)如果replacement是以http://或https://开头,则替换结果会直接以重定向方式返回给客户端;

(3)如果replacement不是以http://或https://开头,将会按次序,依次读取规则,所有规则都处理完成后,把最终结果返回客户端,而不是被某条规则重写后立即返回客户端;

(4)查找时可使用模式,替换为的内容不能使用模式,但可使用后向引用,在nginx中不使用\1,是使用$1来表示引用;

(5) 如果在同一级配置块中存在多个rewrite规则,那么会自下而下逐个检查;被某条件规则替换完成后,会重新一轮的替换检查,因此,隐含有循环机制;[flag]所表示的标志位用于控制此循环机制;

(6)rewrite指令的执行次序,就是写在配置文件中的次序,如果重写时一个规则依次向下循环匹配很多规则时,可使用flag中的break在指定的规则上停止循环,完成最终重写。

例:(1)无错误页面重写

]# vim /etc/nginx/nginx.conf
location / {
index index.html;
rewrite (.*)\/.*\.?.* $1/index.html break;
}

结论:无论用户输入什么资源,都会重写到index.html页面

(2)定义死循环

]# vim /etc/nginx/nginx.conf
location / {
index index.html;
rewrite (.*)\.txt $1.html;
rewrite (.*)\.html $1.txt;
}

结论:浏览器输入http://10.1.1.25/index.txt时,服务器响应码为500(服务器内部错误),此时在两条重写规则任意一条中添加break即可终止循环。

https://www/ilinux.io/images/fish.png—>https://www/ilinux.io/images/fish.jpg

[root@nginx1 /etc/nginx]#vim conf.d/vhost1.conf
server {
        rewrite /(.*)\.png$ /$1.jpg;#只要请求的类型是以.png结尾的,都改为.jpg
[root@nginx1 /etc/nginx]#nginx -t
[root@nginx1 /etc/nginx]#nginx -s reload
[root@nginx1 /etc/nginx]#ls /data/pictures/
fish.jpg  flake.jpg  images
访问png图片,显示jpg图片 

===========================================================================

http://www/ilinux.io—>https://www/ilinux.io

将用户访问80端口时改为8080

[root@nginx1 /etc/nginx/conf.d]#vim vhost1.conf
server {
        #rewrite /(.*)\.png$ /$1.jpg;
        rewrite /(.*)$ https://www/ilinux.io/$1;  #无论用户请求任何内容,都改为https://www/ilinux.io/$1

 ===========================================================================

2、return

return code [text];

return code URL;

return URL;

Default: —

Context: server, location, if

Stops processing and returns the specified code to a client. (停止处理并将指定的代码返回给客户机。)

===========================================================================

3、rewrite_log on | off;

Default: rewrite_log off;

Context: http, server, location, if

是否开启重写日志;启用时,日志信息被发往错误日志

===========================================================================

4、if (condition) { … }

Default: —

Context: server, location

引入一个新的配置上下文 ;条件满足时,执行配置块中的配置指令;server, location;

condition:

比较操作符:

等值比较和不等值比较:  ==    !=

~:模式匹配,左侧字符串是否能被右侧模式匹配,区分字母大小写

~*:模式匹配,左侧字符串是否能被右侧模式匹配,不区分字符大小写

!~:模式不匹配,左侧字符串是否不能被右侧模式匹配,区分字符大小写

!~*:模式不匹配,左侧字符串是否不能被右侧模式匹配,不区分字符大小写

文件及目录存在性判断:

-f|!-f:存在且类型为文件,叹号表示取反

-d|!d:判断为目录

-e|!-e:判断存在

-x|!-x:判断执行权限

例:(1)定义只允许浏览器类型为Chrome和Firefox时,才能将.txt重写为.html

]#vim /etc/nginx/conf.d/vhost.conf
if ($http_user_agent ~* Chrome|Firefox ) {
rewrite (.*)\.txt $1.html break;
}

表示:判断用户的浏览器是否能被Chrome或Firefox匹配,$http_user_agent是其它模块引入的变量

(2)定义如果用户请求方法为post时,返回错误代码及提示给用户

if ($request_method = POST) {

return 405 “Sorry”;

}

(3)定义用户访问的uri中带有admin字样就返回错误代码及提示给用户

]# vim /etc/nginx/nginx.conf
if ($uri ~* .*admin,*) {
return 403 "go away";
}

结论:(1)浏览器输入:www.ilinux.io/admin.html,显示:go away,响应码还是403

         (2)返回指定的错误代码不受自定义的错误代码响应页面影响

===========================================================================

5、set $variable value;

Default: —

Context: server, location, if

用户自定义变量,在nginx中变量无论在定义还是引用都要使用$符号

 ===========================================================================

6、break

语法:Syntax: break;

    Default: —

    Context: server, location, if

停止处理当前ngx_http_rewrite_module指令集。

 ===========================================================================

ngx_http_referer_module模块:

The ngx_http_referer_module module is used to block access to a site for requests with invalid values in the “Referer” header field. (ngx_http_referer_module模块是用来阻止访问一个在referer头域值无效请求的网站,基于引用做访问控制;表示从哪个链接跳转到当前页面)

1、valid_referers none | blocked | server_names | string …;

可实现防盗链拒绝访问,拒绝来自某链接到本网页等功能

定义referer首部的合法可用值;

none:请求报文首部没有referer首部;

blocked:请求报文的referer首部没有值;

server_names:参数,其可以有值作为主机名或主机名模式;

arbitrary_string:直接字符串,但可使用*作通配符;

regular expression:被指定的正则表达式模式匹配到的字符串;要使用~打头,例如 ~.*\.rookie\.com;

配置示例:

valid_referers none block server_names *.rookie.com *.rookie.com rookie.* rookie.* ~\.rookie\.;除这些以外的都是非法引用
if($invalid_referer) {
return 403;
}

其中,$invalid_referer是内嵌变量,表示只有不能被valid_refers指令匹配到的头被归类到invalid_referer;直接调用$invalid_referer变量即可

 ===========================================================================

ngx_http_proxy_module模块:

The ngx_http_proxy_module module allows passing requests to another server.

ngx_http_proxy_module模块允许传递请求到另一个服务器。

1、proxy_pass URL;

Default:—

Context:location, if in location, limit_except

注意:proxy_pass后面的路径不带uri时,其会将location的uri传递给后端主机

server {
...
server_name HOSTNAME;
location /uri/ {
proxy http://hos[:port];
}
...
}

http://HOSTNAME/uri –> http://host/uri

proxy_pass后面的路径是一个uri时,其会将location的uri替换为proxy_pass的uri

server {
...
server_name HOSTNAME;
location /uri/ {
proxy http://host/new_uri/;
}
...
}

http://HOSTNAME/uri/ –> http://host/new_uri/

如果location定义其uri时使用了正则表达式的模式,或在if语句或limt_execept中使用proxy_pass指令,则proxy_pass之后必须不能使用uri; 用户请求时传递的uri将直接附加代理到的服务的之后;

server {
...
server_name HOSTNAME;
location ~|~* /uri/ {
proxy http://host;
}
...
}

http://HOSTNAME/uri/ –> http://host/uri/

 ===========================================================================

2、proxy_set_header field value;

设定发往后端主机的请求报文的请求首部的值;Context: http, server, location

proxy_set_header X-Real-IP  $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for

 ===========================================================================

3、proxy_cache_path;

定义可用于proxy功能的缓存;Context:http

proxy_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time]

 ===========================================================================

4、proxy_cache zone | off;

指明要调用的缓存,或关闭缓存机制;Context: http, server, location

===========================================================================

5、proxy_cache_key string;

缓存中用于“键”的内容;

默认值:proxy_cache_key $scheme$proxy_host$request_uri

 ===========================================================================

6、proxy_cache_valid [code …] time;

定义对特定响应码的响应内容的缓存时长;

定义在http{…}中;

proxy_cache_path /var/cache/nginx/proxy_cache levels=1:1:1 keys_zone=pxycache:20m max_size=1g;

定义在需要调用缓存功能的配置段,例如server{…};

proxy_cache pxycache;

proxy_cache_key $request_uri;

proxy_cache_valid 200 302 301 1h;

proxy_cache_valid any 1m

 ===========================================================================

7、proxy_cache_use_stale

proxy_cache_use_stale error | timeout | invalid_header | updating | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | off …;

Determines in which cases a stale cached response can be used when an error occurs during communication with the proxied server.(在这种情况下,不确定缓存的响应可以用代理服务器的通信过程中出现错误时使用。)

 ===========================================================================

8、proxy_cache_methods GET | HEAD | POST …;

If the client request method is listed in this directive then the response will be cached. “GET” and “HEAD” methods are always added to the list, though it is recommended to specify them explicitly. (如果在这个指令中列出客户机请求方法,那么响应将被缓存。“GET”和“HEAD”方法总是添加到列表中,但建议显式地指定它们。)

===========================================================================

9、proxy_hide_header field;

By default, nginx does not pass the header fields “Date”, “Server”, “X-Pad”, and “X-Accel-…” from the response of a proxied server to a client. The proxy_hide_header directive sets additional fields that will not be passed.(默认情况下,nginx不通过头字段“日期”、“服务器”、“X-PAD”、和“x-accel -…“从响应一个代理服务器的客户端。proxy_hide_header指令集的附加字段那不会被通过。)

===========================================================================

10、proxy_connect_timeout time;      默认为60s

Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.(定义了用于建立与代理服务器连接超时。需要注意的是,这个超时通常不能超过75秒。)

 ===========================================================================

ngx_http_headers_module模块

The ngx_http_headers_module module allows adding the “Expires” and “Cache-Control” header fields, and arbitrary fields, to a response header.(ngx_http_headers_module模块允许添加“过期”和“缓存控制头字段,和任意的领域,一个响应头。)

向由代理服务器响应给客户端的响应报文添加自定义首部,或修改指定首部的值

1、add_header name value [always];

添加自定义首部;

add_header X-Via  $server_addr;

add_header X-Accel $server_name;

===========================================================================

2、expires [modified] time;

expires epoch | max | off;

用于定义Expire或Cache-Control首部的值

 ===========================================================================

ngx_http_fastcgi_module模块:

The ngx_http_fastcgi_module module allows passing requests to a FastCGI server.(ngx_http_fastcgi_module模块允许通过请求FastCGI服务器。)

1、fastcgi_pass address;

Default: —

Context: location, if in location

fastcgi服务器IP地址

===========================================================================

2、fastcgi_index name;

Default: —

Context: http, server, location

fastcgi默认的主页资源

===========================================================================

3、fastcgi_param parameter value [if_not_empty];

Default: —

Context: http, server, location

Sets a parameter that should be passed to the FastCGI server. The value can contain text, variables, and their combination.(设置一个参数,应通过FastCGI服务器。该值可以包含文本、变量和它们的组合。)

配置示例1:

前提:配置好fpm server和mariadb-server服务

安装php-fpm和mysql

yum -y install php-fpm mariadb-server

Nginx配置文件

location ~* \.php$ {
root           /usr/share/nginx/html;
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
include        fastcgi_params;
}

配置示例2:通过/pm_status和/ping来获取fpm server状态信息;

location ~* ^/(pm_status|ping)$ {
include        fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param  SCRIPT_FILENAME  $fastcgi_script_name;
}

===========================================================================

4、fastcgi_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time];

定义fastcgi的缓存;缓存位置为磁盘上的文件系统,由path所指定路径来定义;

levels=levels:缓存目录的层级数量,以及每一级的目录数量;levels=ONE:TWO:THREE

leves=1:2:2

keys_zone=name:size

k/v映射的内存空间的名称及大小

inactive=time

非活动时长

max_size=size

磁盘上用于缓存数据的缓存空间上限

 ===========================================================================

5、fastcgi_cache zone | off;

Default: fastcgi_cache off;

Context: http, server, location

调用指定的缓存空间来缓存数据

 ===========================================================================

6、fastcgi_cache_key string;

Default: —

Context: http, server, location

定义用作缓存项的key的字符串

 ===========================================================================

7、fastcgi_cache_methods GET | HEAD | POST …;

Default: fastcgi_cache_methods GET HEAD;

Context: http, server, location

为哪些请求方法使用缓存

 ===========================================================================

8、fastcgi_cache_min_uses number;

Default: fastcgi_cache_min_uses 1;

Context: http, server, location

缓存空间中的缓存项在inactive定义的非活动时间内至少要被访问到此处所指定的次数方可被认作活动项

 ===========================================================================

9、fastcgi_cache_valid [code …] time;

Default: —

Context: http, server, location

不同的响应码各自的缓存时长;

示例:

http {
...
fastcgi_cache_path /var/cache/nginx/fastcgi_cache levels=1:2:1 keys_zone=fcgi:20m inactive=120s;
...
server {
...
location ~* \.php$ {
...
fastcgi_cache fcgi;
fastcgi_cache_key $request_uri;
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 301 1h;
fastcgi_cache_valid any 1m;
...
}
...
}
...
}

===========================================================================

10、fastcgi_keep_conn on | off;

 Default: fastcgi_keep_conn off;

 Context: http, server, location

By default, a FastCGI server will close a connection right after sending the response. However, when this directive is set to the value on, nginx will instruct a FastCGI server to keep connections open.(默认情况下,一个FastCGI服务器将发送响应后关闭连接正确。然而,当这个指令设置的值,Nginx会指示一个FastCGI服务器保持连接打开。)

===========================================================================







参考资料:

http://wiki.nginx.org/HttpUpstreamConsistentHash

http://wiki.nginx.org/HttpUpstreamFairModule

http://wiki.nginx.org/HttpUpstreamRequestHashModule

http://www.web-polygraph.org/

原创文章,作者:Linux.rookie,如若转载,请注明出处:http://www.178linux.com/80411

(0)
上一篇 2017-07-13 21:49
下一篇 2017-07-14 12:00

相关推荐

  • rpm包管理

    rpm包管理 由于 RPM 是透过预先编译打包成为 RPM 文件格式后,再加以安装的一种方式,还能够进行数据库的记载。 所以 RPM 有以下的优点: RPM 内含已经编译过的程序与配置文件等数据,可以让用户免除重新编译的困扰; RPM 在被安装前,会先检查系统的硬盘容量、操作系统版本等,可避免档案被错误安装; RPM 档案本身提供软件版本信息、相依属性软件名…

    Linux干货 2016-08-21
  • nfs,samba同步LAMP与Mysql

    使用nfs功能实现WEB页面同步     拓扑图见NFS实现LAMP冗余:     目的:使用网络文件系实现LAMP的分步式资源共享    配置步骤:    配置test1:搭建NFS环境:&nbsp…

    2017-04-26
  • find命令总结

    用途:     find命令用来在文件层级结构中搜索跟条件匹配的文件 语法:     find [OPTIONS] [查找起始路径] [查找条件] [处理动作]     查找起始路径:指定具体搜索起始路径。默认为当前目录  &nb…

    Linux干货 2016-09-19
  • 内键命令和外部命令

    命令的基本格式 COMMAND  [OPTIONS…]  [ARGUMENTS…]        命令 (COMMAND)       OPTIONS(选项):用于启用或关闭命令的某个或某些功能      …

    2017-05-23
  • 1017作业

    1 生产环境发现一台服务器系统时间产生偏差,造成服务异常,请帮忙校正 ##先分析硬件时间不对还是系统时间不对,如果是系统时间不对: [root@localhost ~]# hwclock -w [root@localhost ~]#  ##如果是硬件时间不对: [root@localhost ~]#…

    Linux干货 2016-10-18