使用nginx中的map做生产与测试分离时,一些注意地方

http {
    ...
    #解决出现could not be resolved
    resolver 8.8.8.8; 
    #解决下滑线不能使用问题
	underscores_in_headers on;
    #当请求中 header有自定义参数app_version时,进行判断要使用哪个域名
    #我这里对版本进行判断
	 map $http_app_version $app_version_upstream_api {  
		default api.xxxxx.com;
		1.8.0 test_api.xxxxx.com;
  }

server {
        listen       443 ssl;
        server_name  api.xxxxx.com;

        ssl_certificate      xxxxx/xxxxx.pem;
        ssl_certificate_key  xxxxx/xxxxx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
		

        location / {
		    client_max_body_size    10m;
           #$app_version_upstream_api看是一个方法,调用上面的map,然后进行赋值
           proxy_pass  http://$app_version_upstream_api;

	       # Host配置以及域名传递
           #下面一这行一定要注释掉,不然会出现各种情报错,如503
           #proxy_set_header Host $host;

          ....
        }
        #让日志文件按日期进行记录
        if ($time_iso8601 ~ '(\d{4}-\d{2}-\d{2})') {  
                set $tttt $1;  
        }
        access_log logs/apixxxxxcom/$tttt.log main;
    }
    #下面是当请求为 https://yyyy.xxxx.com/appapi/ 时请求向上面的api.xxxx.com
    server {
        listen       443 ssl;
        server_name  yyyy.xxxxx.com;

        ssl_certificate      xxxxx/xxxxx.pem;
        ssl_certificate_key  xxxxx/xxxxx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
		


		root D:\www\yyyy;
		index index.html;
		
		location /appapi/ {
			client_max_body_size    10m;
            #注:proxy_pass 一定要使用 https ,暂时找不到更好的方法
            proxy_pass  https://api.xxxxx.com/;
			# Host配置以及域名传递
            #注:Host一定要配为api.xxxxx.com
		   proxy_set_header Host api.xxxxx.com;
		  ...
        }
       ...
    }
}

 

你可能感兴趣的:(运维,nginx,nginx)