声明:本站文章均为作者个人原创,图片均为实际截图。如有需要请收藏网站,禁止转载,谢谢配合!!!

1、常用框架配置伪静态

将所有请求转发到某个文件上面

location / {
 if (!-e $request_filename){
  rewrite  ^(.*)$  /index.php?s=$1  last;   break;
 }
}

2、转发

访问 /a/* 时候,将请求转发到 http://def.com:1002/b

location /a {
    proxy_redirect off;
    proxy_set_header Host admin.tianhongmuchen.com;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://def.com:1002/b;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
}

3、某个文件

将请求转发到某个文件上,常用于vue打包后的页面 /h5/#/…

location /h5 {
    try_files $uri $uri/ /h5/index.html;
}

4、图片等资源文件配置跨域

请求这些类型的文件时候,加上允许跨域的header

location ~* \.(gif|jpg|jpeg|png|bmp|swf)$ {
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
}

5、配置fastcgi时间

用于解决php执行时间过长出现404 not found的问题

fastcgi_connect_timeout 600;
fastcgi_read_timeout 600;
fastcgi_send_timeout 600;