问题场景:

在上次app改版中,我们把app对应的站外项目进行了重构,同时也针对域名进行了统一的规划,但是因为公司人员调整,造成了安卓app版本落后一个,由此导致接口上线后,安卓中的分享地址还是之前的,许多功能分享出来后没有数据,在不重新发apk的情况下,我想到了利用nginx的301重定向,来永久改变这个地址,

解决方案:

打开nginx,之前已经配置过了反向代理,这里不做重点描述

配置如下

server {
        listen       80;
        server_name  xx.yy.com;
        location / {
        proxy_pass http://10.10.10.136:80;
   }
		
        access_log  /var/log/nginx/xx.yy.com.access.log;
        error_log  /var/log/nginx/xx.yy.com.error.log  info;
}

更改这个配置

server {
        listen       80;
        server_name  xx.yy.com;
        location / {
        proxy_pass http://10.10.10.136:80;
   }
		if ($request_filename ~* a/fx/envelope.html) { 
			rewrite ^/(.*)$ http://zz.yy.com/a/jsp/fxf/share/envelope.jsp?$args? permanent; 
		}
		if ($request_filename ~* ffyy/fx/replyLetter.html) { 
			rewrite ^/(.*)$ http://zz.yy.com/a/jsp/fxf/share/replyLetter.jsp?$args? permanent; 
		}
		
        access_log  /var/log/nginx/xx.yy.com.access.log;
 error_log  /var/log/nginx/xx.yy.com.error.log  info;

$args, 请求中的参数;
$content_length, HTTP请求信息里的"Content-Length";
$content_type, 请求信息里的"Content-Type";
$document_root, 针对当前请求的根路径设置值;
$document_uri, 与$uri相同;
$host, 请求信息中的"Host",如果请求中没有Host行,则等于设置的服务器名;
$limit_rate, 对连接速率的限制;
$request_method, 请求的方法,比如"GET"、"POST"等;
$remote_addr, 客户端地址;
$remote_port, 客户端端口号;
$remote_user, 客户端用户名,认证用;
$request_filename, 当前请求的文件路径名
$request_body_file
$request_uri, 请求的URI,带查询字符串;
$query_string, 与$args相同;
$scheme, 所用的协议,比如http或者是https,比如rewrite ^(.+)$ $scheme://example.com$1 redirect;
$server_protocol, 请求的协议版本,"HTTP/1.0"或"HTTP/1.1";
$server_addr, 服务器地址,如果没有用listen指明服务器地址,使用这个变量将发起一次系统调用以取得地址(造成资源浪费);
$server_name, 请求到达的服务器名;
$server_port, 请求到达的服务器端口号;
$uri, 请求的URI,可能和最初的值有不同,比如经过重定向之类的。