在系统还没有做集群的情况下,直接重启项目时刚好用户在使用的话,一般都会受到投诉,那么使用nginx返回类似“系统维护”的提示信息并且提前在应用上面做通知才是合适的做法

 

那么记录一下nginx里面的配置

server{
        listen xx;
        add_header Content-Type 'text/html; charset=utf-8';
        return 200 '{"msg":"系统临时维护中,请您耐心等待","code":10,"data":""}';

}

listen xx 表示监听的端口,我常用的做法时在维护的时候使用防火墙端口转发过来

第二行add_header解决的是浏览器中文乱码的问题

第三行就是你所要提示的信息格式

 

1、返回文本格式

1
2
3
4
location ~ ^/get_text {
  default_type text/html;
  return 200 'hello world!';
}

2、返回json格式

1
2
3
4
location ~ ^/get_json {
  default_type application/json;
  return 200 '{"status":"success","result":"hello world!"}';
}

3、也可以简单的根据请求的URL返回不同的字符串

1
2
3
4
5
6
location ~ ^/get_text/article/(.*)_(\d+).html$ {
  default_type text/html;
  set $s $1;
  set $d $2;
  return 200 str:$s$d;
}

4、返回的字符集设置,默认是以GBK字符集返回

1
2
3
4
5
location ~ ^/get_text {
  default_type text/html;
  add_header Content-Type 'text/html; charset=utf-8';
  return 200 '你好,世界!'; 
}

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-07
  • 2022-01-27
  • 2021-08-26
  • 2021-07-24
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2022-12-23
  • 2021-12-02
  • 2022-03-01
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案