秀才


  • Home

  • About

  • Tags

  • Archives

  • Search

函数

Posted on 2017-04-18 | Visitors:

concat

1
2
3
4
// 将id name work_date连接起来
CONCAT(id, name, work_date)
// 在like中用到:
CONCAT('%',:v" . self::$number . ",'%')

基本设置

Posted on 2017-04-15 | Visitors:

只允许本机访问

一般用于设置内部服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen 8888;
server_name localhost;
root /www/vux/vux/my;
location / {
allow 127.0.0.1;
deny all;
try_files $uri $uri/ /index.php?$query_string;
autoindex on;
index index.html index.htm index.php;
include /etc/nginx/conf.d/php-fpm;
}
}

域名(端口)转发

一般用于前后端完全分离的设计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
server {
listen 80;
server_name douniu.kouhuo.site;
location / {
index index.html index.htm index.php;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
location /api {
#rewrite ^.+api/?(.*)$ /$1 break;
proxy_redirect off;
proxy_set_header Host $host; #要转发的host
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8888/; #设置要转发的ip(域名)端口
}
}

访问php动态资源(fastcgi)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server {
listen 80;
server_name local.ladmin.com local.ladmin.com;
root "D:/items/laravel/lesson-admin/public";
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
#autoindex on;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
add_header Access-Control-Allow-Credentials "true";
add_header Access-Control-Allow-Headers "Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With";
if ($request_method = 'OPTIONS'){
return 204;
}
}
}

配置header头的最大字节数

1
2
3
4
5
6
7
server{
...
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
...
}

设置超时时间

1
2
3
4
5
6
7
server{
...
proxy_connect_timeout 360;
proxy_send_timeout 360;
proxy_read_timeout 360;
...
}

rewrite 规则

Posted on 2017-04-13 | Visitors:

1. location正则写法

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
location  = / {
# 精确匹配 / ,主机名后面不能带任何字符串
[ configuration A ]
}
location / {
# 因为所有的地址都以 / 开头,所以这条规则将匹配到所有请求
# 但是正则和最长字符串会优先匹配
[ configuration B ]
}
location /documents/ {
# 匹配任何以 /documents/ 开头的地址,匹配符合以后,还要继续往下搜索
# 只有后面的正则表达式没有匹配到时,这一条才会采用这一条
[ configuration C ]
}
location ~ /documents/Abc {
# 匹配任何以 /documents/Abc 开头的地址,匹配符合以后,还要继续往下搜索
# 只有后面的正则表达式没有匹配到时,这一条才会采用这一条
[ configuration CC ]
}
location ^~ /images/ {
# 匹配任何以 /images/ 开头的地址,匹配符合以后,停止往下搜索正则,采用这一条。
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ {
# 匹配所有以 gif,jpg或jpeg 结尾的请求
# 然而,所有请求 /images/ 下的图片会被 config D 处理,因为 ^~ 到达不了这一条正则
[ configuration E ]
}
location /images/ {
# 字符匹配到 /images/,继续往下,会发现 ^~ 存在
[ configuration F ]
}
location /images/abc {
# 最长字符匹配到 /images/abc,继续往下,会发现 ^~ 存在
# F与G的放置顺序是没有关系的
[ configuration G ]
}
location ~ /images/abc/ {
# 只有去掉 config D 才有效:先最长匹配 config G 开头的地址,继续往下搜索,匹配到这一条正则,采用
[ configuration H ]
}
location ~* /js/.*/\.js

  • 已=开头表示精确匹配
    如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。
  • ^~ 开头表示uri以某个常规字符串开头,不是正则匹配
  • ~ 开头表示区分大小写的正则匹配;
  • ~* 开头表示不区分大小写的正则匹配
  • / 通用匹配, 如果没有其它匹配,任何请求都会匹配到
  • 顺序 no优先级:
    (location =) > (location 完整路径) > (location ^~ 路径) > (location ~,~* 正则顺序) > (location 部分起始路径) > (/)
1…67

chimps

63 posts
32 tags
RSS
© 京ICP备19001740号-1 2020 chimps
Powered by Hexo
|
Theme — NexT.Gemini v5.1.4