nginx遇到的配置的坑

坑1 ,302重定向跳转问题  

第一步以为要在nginx里面配置, 所以装了more-header 

设置了proxy_set_header Cookie $http_cookie;           
           more_set_headers "Location: ";

----302重定向没问题了,但是出现了第二个请求404页面,session也写入了,仍然404;

此时:

开始尝试写接口,证明session已传入头部请求

代码一HttpClientUtil.class

package com.commons;


import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;


import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;


public class HttpClientUtil {
public String doPost(String url,Map<String,String> map,String charset,String sessionId){  
        HttpClient httpClient = null;  
        HttpPost httpPost = null;  
        String result = null;  
        try{  
            httpClient = new SSLClient();  
            httpPost = new HttpPost(url);  
           /* //设置参数  
            List<NameValuePair> list = new ArrayList<NameValuePair>();  
            Iterator iterator = map.entrySet().iterator();  
            while(iterator.hasNext()){  
                Entry<String,String> elem = (Entry<String, String>) iterator.next();  
                list.add(new BasicNameValuePair(elem.getKey(),elem.getValue()));  
            }  
            if(list.size() > 0){  
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset);  
                httpPost.setEntity(entity);  
            }  */
            if(sessionId != null){
            httpPost.setHeader("Cookie","SFPAY_JSESSIONID="+sessionId);
            httpPost.setHeader("Content-Type","application/octet-stream");
             }
            HttpResponse response = httpClient.execute(httpPost);  
            System.out.println("response" + response);
            if(response != null){  
            int sessionIdIndex=response.toString().indexOf("SFPAY_JSESSIONID");
    if(sessionIdIndex >0){
    int begin=response.toString().indexOf('=', sessionIdIndex);
    int end=response.toString().indexOf(';', sessionIdIndex);
    String returnSessionId=response.toString().substring(begin+1,end);
       sessionId = returnSessionId;
       System.out.println("sessionId "+ sessionId);
    }
            }  
        }catch(Exception ex){  
            ex.printStackTrace();  
        }  
        return sessionId;  
    }  



public String doGet(String url,String charset,String sessionId){  
        HttpClient httpClient = null;  
        HttpGet httpGet= null; 
        
        try{  
            httpClient = new SSLClient();  
            httpGet   = new HttpGet(url);  
           /* //设置参数  
            List<NameValuePair> list = new ArrayList<NameValuePair>();  
            Iterator iterator = map.entrySet().iterator();  
            while(iterator.hasNext()){  
                Entry<String,String> elem = (Entry<String, String>) iterator.next();  
                list.add(new BasicNameValuePair(elem.getKey(),elem.getValue()));  
            }  
            if(list.size() > 0){  
                UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,charset);  
                httpPost.setEntity(entity);  
            }  */
            if(sessionId != null){
            httpGet.setHeader("Cookie","SFPAY_JSESSIONID="+sessionId);
            httpGet.setHeader("Content-Type","application/octet-stream");
             }
            HttpResponse response = httpClient.execute(httpGet);  
            System.out.println("response" + response);
            if(response != null){  
            int sessionIdIndex=response.toString().indexOf("SFPAY_JSESSIONID");
    if(sessionIdIndex >0){
    int begin=response.toString().indexOf('=', sessionIdIndex);
    int end=response.toString().indexOf(';', sessionIdIndex);
    String returnSessionId=response.toString().substring(begin+1,end);
       sessionId = returnSessionId;
       System.out.println("sessionId "+ sessionId);
    }
            }  
        }catch(Exception ex){  
            ex.printStackTrace();  
        }  
        return sessionId;  
    }  
public static void main(String[] args){
HttpClientUtil http = new HttpClientUtil();
String sessionId = http.doPost("http://url1", null,"UTF-8",null);
String session2 =sessionId ;
http.doGet("http://url2","UTF-8",session2);

}
}

到了这一步测试仍然不行,直接在nginx端报出了404页面,没有进入到实际的业务环境。

仔细查看配置文件,发现自己配置了nginxStatic path; 将nginxStatic 的内容复制过来就没有404报错啦  /(ㄒoㄒ)/~~




总结:

1. 配置nginx 不用太复杂

2. 静态js,图片都是存放在nginx服务器的安装目录下,既一般为/usr/local/nginx 目录下。

3.重定向地址是代码配置里面改的,修改代码的配置就行(说明对公司应用系统架构不熟 /(ㄒoㄒ)/~~)


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值