内容列表
nginx添加反向代理
#PROXY-START/ location ~* \.(php|jsp|cgi|asp|aspx)$ { proxy_pass https://xxxx1.com; proxy_set_header Host xxxx1.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; } location / { proxy_pass https://xxxx1.com; proxy_set_header Host xxxx1.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; add_header X-Cache $upstream_cache_status; #Set Nginx Cache add_header Cache-Control no-cache; expires 12h; } #PROXY-END/ //$upstream_cache_status //HIT:表示请求的资源从 Nginx 的缓存中获取到了,即命中了缓存。这意味着 Nginx 没有将请求转发到后端服务器,而是直接从本地缓存中取出数据返回给客户端。 //MISS:表示请求的资源在 Nginx 的缓存中未找到,即缓存未命中。此时 Nginx 会将请求转发到后端服务器获取数据,然后将数据返回给客户端,同时可能会将数据缓存起来以便后续请求使用。 //EXPIRED:表示缓存中的资源已经过期。Nginx 仍然会将请求转发到后端服务器,获取最新的资源数据返回给客户端,并更新缓存(如果配置允许)。 //STALE:当 Nginx 配置了在后端服务器出现错误(如 error、timeout、invalid_header 以及特定的 HTTP 状态码如 http_500、http_502 等)时使用缓存中的旧数据进行响应,就可能出现 STALE 状态,表示返回的是缓存中的旧数据 。
2024-06-19
阿里云翻译代码
private function doTrans($text){ try { if (strlen($text) > 5000) { $max_len = strlen($text) ; $len = 0; $res = ''; while ($len < $max_len ){ $res .= $this->transText(substr($text,$len,5000)); $len = $len + 5000; } } else { $res = $this->transText($text); } }catch (\Throwable $e) { $res = false; } return $res; } private function transText($text){ require_once dirname(dirname(__DIR__)).'/ali/vendor/autoload.php'; $rt = ''; $config = new \Darabonba\OpenApi\Models\Config([ // 必填,您的 AccessKey ID "accessKeyId" => 'xxxxxx', // 必填,您的 AccessKey Secret "accessKeySecret" => 'xxxxxx' ]); // Endpoint 请参考 https://api.aliyun.com/product/alimt $config->endpoint = "mt.aliyuncs.com"; $client = new \AlibabaCloud\SDK\Alimt\V20181012\Alimt($config); $translateGeneralRequest = new \AlibabaCloud\SDK\Alimt\V20181012\Models\TranslateGeneralRequest([ "formatType" => "text", "sourceLanguage" => "id", "targetLanguage" => "zh", "sourceText" => $text, "scene" => "general", "context" => "" ]); $runtime = new \AlibabaCloud\Tea\Utils\Utils\RuntimeOptions([]); try { // 复制代码运行请自行打印 API 的返回值 $res = $client->translateGeneralWithOptions($translateGeneralRequest, $runtime); if($res->statusCode == 200){ if($res->body->data->translated){ $rt = $res->body->data->translated; } } } catch (\Exception $error) { // var_dump($error->getMessage().$error->getFile().$error->getLine()); ref_log_error(0,'翻译异常',$error->getMessage().$error->getFile().$error->getLine()); } return $rt; }
2024-04-18