首页
苏兮影视
随笔记
壁纸
更多
直播
时光轴
友联
关于
统计
Search
1
软件添加id功能按钮
708 阅读
2
v2ray节点搭建
507 阅读
3
typecho非常有特色的模块
460 阅读
4
QQxml消息卡片生成源码
421 阅读
5
Linux下提权常用小命令
366 阅读
谈天说地
建站源码
经验教程
资源分享
动漫美图
登录
Search
标签搜索
java
flutter
springboot
rust
安卓
linux
vue
docker
joe
快捷键
git
fish shell
maven
redis
netty
dart
groovy
js
设计模式
rpc
尽意
累计撰写
95
篇文章
累计收到
38
条评论
首页
栏目
谈天说地
建站源码
经验教程
资源分享
动漫美图
页面
苏兮影视
随笔记
壁纸
直播
时光轴
友联
关于
统计
搜索到
5
篇与
的结果
配置和使用 CDN 加速网站
在现代网站建设中,为了提高访问速度和用户体验,使用内容分发网络(CDN)成为了一个普遍的选择。本文将带你了解 CDN 配置的基本流程,帮助你为网站实现高效的加速和稳定性。一、什么是 CDN?CDN,全称为内容分发网络(Content Delivery Network),是一种通过将网站内容分发到全球不同的节点来加速用户访问的技术。通过 CDN,当用户请求访问时,系统会将请求路由到离用户最近的服务器节点,减少响应时间并提高加载速度。二、CDN 配置的基本步骤以下是如何将 CDN 集成到你的网站的详细步骤:1. 注册并登录 CDN 平台首先,选择一个适合的 CDN 服务提供商,例如 腾讯云、阿里云、或本地云服务商。注册并登录 CDN 服务控制台。2. 添加加速域名在 CDN 管理平台上,添加你想加速的域名,例如 pan.example.com。CDN 平台会为你生成一个唯一的 CNAME 地址,例如 cdn.exampleprovider.com,这是用于 DNS 解析的。3. 配置源站源站域名:设置为网站服务器的实际域名或 IP 地址,如 pan.example.com 或服务器的公共 IP。回源 Host:通常设置为源站域名 pan.example.com。这确保了回源请求中的 Host 头与原始请求一致。如果有特殊需求,可根据情况调整。4. DNS 解析配置在你的域名服务商的 DNS 控制台中,将 pan.example.com 的 DNS 记录配置为 CNAME,并指向 CDN 提供的 CNAME 地址 cdn.exampleprovider.com。保存配置并等待 DNS 解析生效,这个过程可能需要几分钟到几小时。5. 调整回源设置回源方式:选择通过域名或 IP 进行回源。如果使用 IP,可以避免循环解析问题,但需要保证 IP 的稳定性。缓存策略:根据你的网站内容类型来设置缓存时间,例如静态资源可以长时间缓存,而动态内容应设置较短的缓存时间或不缓存。回源协议:设置为 HTTP 或 HTTPS,根据你网站的安全需求选择合适的协议。6. 检查配置和测试完成配置后,通过浏览器或网络工具访问 pan.example.com,确认访问流量已经通过 CDN 节点加速。同时,可以在 CDN 平台查看访问日志和缓存命中率,并根据需要优化缓存策略。三、常见问题及解决方案1. 加速域名与源站域名相同在某些情况下,你可能想将加速域名(如 pan.example.com)与源站域名设置为相同。这是可行的,但需注意以下几点:DNS 配置:确保加速域名正确解析为 CDN 提供的 CNAME 地址。回源避免循环:CDN 配置时,可以选择使用源站 IP 来避免请求回源至 CDN 本身。2. 回源 Host 的选择回源 Host 设置为源站域名(如 pan.example.com)即可。如果源站有特殊的 Host 验证需求,确保该 Host 设置能够被服务器接受和处理。3. 配置未生效或请求循环检查 DNS 解析是否正确指向 CDN 的 CNAME 地址。确认 CDN 配置中的源站地址无误,确保它不会导致回源请求指向 CDN 节点。四、优化 CDN 的使用分层缓存:根据网站的访问模式和流量来源设置多级缓存策略,以实现更高的缓存命中率。带宽和流量监控:定期检查 CDN 提供商的控制台,查看带宽使用和流量统计,避免超出预算。安全功能:使用 CDN 提供的额外安全功能,如 DDoS 防护和 Web 应用防火墙(WAF),来保护网站免受攻击。
2024年11月06日
24 阅读
0 评论
3 点赞
java使用日志
maven工程中引入日志门面框架 <!--日志门面--> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>2.0.7</version> </dependency>引入日志实现框架<!--logback 日志实现--> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.4.8</version> </dependency>在resource目录下配置 logback.xml 文件<?xml version="1.0" encoding="UTF-8" ?> <configuration> <!-- 配置集中管理属性 我们可以直接修改属性的value值 格式:${name} --> <property name="pattern" value="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} %c %M %L [%thread] %m%n"></property> <!-- 日志输出格式: %-5level %d{yyyy-MM-dd HH:mm:ss.SSS}日期 %c类的完整名称 %M为方法 %L为行号 %thread为线程名称 %m或者$msg为信息 %n换行 --> <!--定义日志文件保存路径属性--> <!--win写/log会在盘符根目录,logs/在项目根目录--> <property name="log_dir" value="logs/"></property> <!--控制日志输出的appender--> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <!--控制输出流对象 默认System.out 改为System.err--> <target>System.err</target> <!--日志消息格式配置--> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>${pattern}</pattern> </encoder> </appender> <!--日志文件输出的appender--> <appender name="file" class="ch.qos.logback.core.FileAppender"> <!--日志文件保存路径--> <file>${log_dir}/logback.log</file> <!--日志消息格式配置--> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern>${pattern}</pattern> </encoder> </appender> <!--root logger 配置--> <root level="ALL"> <appender-ref ref="console"/> <!-- <appender-ref ref="file"/>--> </root> </configuration>在java文件中引入使用public static final Logger logger = LoggerFactory.getLogger(Application.class);finish
2024年02月03日
45 阅读
0 评论
2 点赞
2021-01-24
php表单提交并发送邮件给某个邮箱(示例源码)
首先,建立一个index.html文件,代码如下:<html> <head> <title>Simple Send Mail </title> </head> <body> <h1>Mail Form</h1> <form name="form1" method="post" action="mail.php"> <table> <tr><td><b>To</b></td><td> <input type="text" name="mailto" size="35"> </td></tr> <tr><td><b>Subject</b></td> <td><input type="text" name="mailsubject" size="35"></td> </tr> <tr><td><b>Message</b></td> <td> <textarea name="mailbody" cols="50" rows="7"></textarea> </td> </tr> <tr><td colspan="2"> <input type="submit" name="Submit" value="Send"> </td> </tr> </table> </form> </body> </html>然后新建一个“mail.php”文档把传输的文档进行发送<?php $stm="邮件内容"; require("smtp.php"); ########################################## $smtpserver = "smtp.qq.com";//SMTP服务器 $smtpserverport = "465";//SMTP服务器端口 $smtpusermail = "XXX@qq.com";//SMTP服务器的用户邮箱 $smtpemailto = "AAA@qq.com";//发送给谁 $smtpuser = "XXX@qq.com";//SMTP服务器的用户帐号 $smtppass = "666";//SMTP服务器的用户密码 $mailsubject = "666 ";//邮件主题 $mailbody = $stm;//邮件内容 $mailtype = "HTML";//邮件格式(HTML/TXT),TXT为文本邮件 ########################################## $smtp = new smtp($smtpserver,$smtpserverport,true,$smtpuser,$smtppass);//这里面的一个true是表示使用身份验证,否则不使用身份验证. $smtp->debug = TRUE;//是否显示发送的调试信息 $smtp->sendmail($smtpemailto, $smtpusermail, $mailsubject, $mailbody, $mailtype); echo "<script>alert('邮件发送成功');parent.document.ADDUser.cheheh.click();</script>"; exit; } ?> 最后编写一个邮件类“smtp.php”<?php class smtp { /* Public Variables */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; /* Private Variables */ var $sock; /* Constractor */ function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass) { $this->debug = FALSE; $this->smtp_port = $smtp_port; $this->relay_host = $relay_host; $this->time_out = 30; //is used in fsockopen() $this->auth = $auth;//auth $this->user = $user; $this->pass = $pass; $this->host_name = "localhost"; //is used in HELO command $this->log_file = ""; $this->sock = FALSE; } /* Main Function */ function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "") { $mail_from = $this->get_address($this->strip_comment($from)); $body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body); $header .= "MIME-Version:1.0\r\n"; if($mailtype=="HTML") { $header .= "Content-Type:text/html\r\n"; } $header .= "To: ".$to."\r\n"; if ($cc != "") { $header .= "Cc: ".$cc."\r\n"; } $header .= "From: $from<".$from.">\r\n"; $header .= "Subject: ".$subject."\r\n"; $header .= $additional_headers; $header .= "Date: ".date("r")."\r\n"; $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n"; list($msec, $sec) = explode(" ", microtime()); $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n"; $TO = explode(",", $this->strip_comment($to)); if ($cc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($cc))); } if ($bcc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($bcc))); } $sent = TRUE; foreach ($TO as $rcpt_to) { $rcpt_to = $this->get_address($rcpt_to); if (!$this->smtp_sockopen($rcpt_to)) { $this->log_write("Error: Cannot send email to ".$rcpt_to."\n"); $sent = FALSE; continue; } if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) { $this->log_write("E-mail has been sent to <".$rcpt_to.">\n"); } else { $this->log_write("Error: Cannot send email to <".$rcpt_to.">\n"); $sent = FALSE; } fclose($this->sock); $this->log_write("Disconnected from remote host\n"); } return $sent; } /* Private Functions */ function smtp_send($helo, $from, $to, $header, $body = "") { if (!$this->smtp_putcmd("HELO", $helo)) { return $this->smtp_error("sending HELO command"); } #auth if($this->auth) { if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) { return $this->smtp_error("sending HELO command"); } if (!$this->smtp_putcmd("", base64_encode($this->pass))) { return $this->smtp_error("sending HELO command"); } } if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) { return $this->smtp_error("sending MAIL FROM command"); } if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) { return $this->smtp_error("sending RCPT TO command"); } if (!$this->smtp_putcmd("DATA")) { return $this->smtp_error("sending DATA command"); } if (!$this->smtp_message($header, $body)) { return $this->smtp_error("sending message"); } if (!$this->smtp_eom()) { return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]"); } if (!$this->smtp_putcmd("QUIT")) { return $this->smtp_error("sending QUIT command"); } return TRUE; } function smtp_sockopen($address) { if ($this->relay_host == "") { return $this->smtp_sockopen_mx($address); } else { return $this->smtp_sockopen_relay(); } } function smtp_sockopen_relay() { $this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); return FALSE; } $this->log_write("Connected to relay host ".$this->relay_host."\n"); return TRUE;; } function smtp_sockopen_mx($address) { $domain = ereg_replace("^.+@([^@]+)$", "\1", $address); if (!@getmxrr($domain, $MXHOSTS)) { $this->log_write("Error: Cannot resolve MX \"".$domain."\"\n"); return FALSE; } foreach ($MXHOSTS as $host) { $this->log_write("Trying to ".$host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Warning: Cannot connect to mx host ".$host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); continue; } $this->log_write("Connected to mx host ".$host."\n"); return TRUE; } $this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n"); return FALSE; } function smtp_message($header, $body) { fputs($this->sock, $header."\r\n".$body); $this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> ")); return TRUE; } function smtp_eom() { fputs($this->sock, "\r\n.\r\n"); $this->smtp_debug(". [EOM]\n"); return $this->smtp_ok(); } function smtp_ok() { $response = str_replace("\r\n", "", fgets($this->sock, 512)); $this->smtp_debug($response."\n"); if (!ereg("^[23]", $response)) { fputs($this->sock, "QUIT\r\n"); fgets($this->sock, 512); $this->log_write("Error: Remote host returned \"".$response."\"\n"); return FALSE; } return TRUE; } function smtp_putcmd($cmd, $arg = "") { if ($arg != "") { if($cmd=="") { $cmd = $arg; } else { $cmd = $cmd." ".$arg; } } fputs($this->sock, $cmd."\r\n"); $this->smtp_debug("> ".$cmd."\n"); return $this->smtp_ok(); } function smtp_error($string) { $this->log_write("Error: Error occurred while ".$string.".\n"); return FALSE; } function log_write($message) { $this->smtp_debug($message); if ($this->log_file == "") { return TRUE; } $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message; if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) { $this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n"); return FALSE;; } flock($fp, LOCK_EX); fputs($fp, $message); fclose($fp); return TRUE; } function strip_comment($address) { $comment = "\([^()]*\)"; while (ereg($comment, $address)) { $address = ereg_replace($comment, "", $address); } return $address; } function get_address($address) { $address = ereg_replace("([ \t\r\n])+", "", $address); $address = ereg_replace("^.*<(.+)>.*$", "\1", $address); return $address; } function smtp_debug($message) { if ($this->debug) { //echo $message; } } } ?><?php class smtp { /* Public Variables */ var $smtp_port; var $time_out; var $host_name; var $log_file; var $relay_host; var $debug; var $auth; var $user; var $pass; /* Private Variables */ var $sock; /* Constractor */ function smtp($relay_host = "", $smtp_port = 25,$auth = false,$user,$pass) { $this->debug = FALSE; $this->smtp_port = $smtp_port; $this->relay_host = $relay_host; $this->time_out = 30; //is used in fsockopen() $this->auth = $auth;//auth $this->user = $user; $this->pass = $pass; $this->host_name = "localhost"; //is used in HELO command $this->log_file = ""; $this->sock = FALSE; } /* Main Function */ function sendmail($to, $from, $subject = "", $body = "", $mailtype, $cc = "", $bcc = "", $additional_headers = "") { $mail_from = $this->get_address($this->strip_comment($from)); $body = ereg_replace("(^|(\r\n))(\.)", "\1.\3", $body); $header .= "MIME-Version:1.0\r\n"; if($mailtype=="HTML") { $header .= "Content-Type:text/html\r\n"; } $header .= "To: ".$to."\r\n"; if ($cc != "") { $header .= "Cc: ".$cc."\r\n"; } $header .= "From: $from<".$from.">\r\n"; $header .= "Subject: ".$subject."\r\n"; $header .= $additional_headers; $header .= "Date: ".date("r")."\r\n"; $header .= "X-Mailer:By Redhat (PHP/".phpversion().")\r\n"; list($msec, $sec) = explode(" ", microtime()); $header .= "Message-ID: <".date("YmdHis", $sec).".".($msec*1000000).".".$mail_from.">\r\n"; $TO = explode(",", $this->strip_comment($to)); if ($cc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($cc))); } if ($bcc != "") { $TO = array_merge($TO, explode(",", $this->strip_comment($bcc))); } $sent = TRUE; foreach ($TO as $rcpt_to) { $rcpt_to = $this->get_address($rcpt_to); if (!$this->smtp_sockopen($rcpt_to)) { $this->log_write("Error: Cannot send email to ".$rcpt_to."\n"); $sent = FALSE; continue; } if ($this->smtp_send($this->host_name, $mail_from, $rcpt_to, $header, $body)) { $this->log_write("E-mail has been sent to <".$rcpt_to.">\n"); } else { $this->log_write("Error: Cannot send email to <".$rcpt_to.">\n"); $sent = FALSE; } fclose($this->sock); $this->log_write("Disconnected from remote host\n"); } return $sent; } /* Private Functions */ function smtp_send($helo, $from, $to, $header, $body = "") { if (!$this->smtp_putcmd("HELO", $helo)) { return $this->smtp_error("sending HELO command"); } #auth if($this->auth) { if (!$this->smtp_putcmd("AUTH LOGIN", base64_encode($this->user))) { return $this->smtp_error("sending HELO command"); } if (!$this->smtp_putcmd("", base64_encode($this->pass))) { return $this->smtp_error("sending HELO command"); } } if (!$this->smtp_putcmd("MAIL", "FROM:<".$from.">")) { return $this->smtp_error("sending MAIL FROM command"); } if (!$this->smtp_putcmd("RCPT", "TO:<".$to.">")) { return $this->smtp_error("sending RCPT TO command"); } if (!$this->smtp_putcmd("DATA")) { return $this->smtp_error("sending DATA command"); } if (!$this->smtp_message($header, $body)) { return $this->smtp_error("sending message"); } if (!$this->smtp_eom()) { return $this->smtp_error("sending <CR><LF>.<CR><LF> [EOM]"); } if (!$this->smtp_putcmd("QUIT")) { return $this->smtp_error("sending QUIT command"); } return TRUE; } function smtp_sockopen($address) { if ($this->relay_host == "") { return $this->smtp_sockopen_mx($address); } else { return $this->smtp_sockopen_relay(); } } function smtp_sockopen_relay() { $this->log_write("Trying to ".$this->relay_host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($this->relay_host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Error: Cannot connenct to relay host ".$this->relay_host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); return FALSE; } $this->log_write("Connected to relay host ".$this->relay_host."\n"); return TRUE;; } function smtp_sockopen_mx($address) { $domain = ereg_replace("^.+@([^@]+)$", "\1", $address); if (!@getmxrr($domain, $MXHOSTS)) { $this->log_write("Error: Cannot resolve MX \"".$domain."\"\n"); return FALSE; } foreach ($MXHOSTS as $host) { $this->log_write("Trying to ".$host.":".$this->smtp_port."\n"); $this->sock = @fsockopen($host, $this->smtp_port, $errno, $errstr, $this->time_out); if (!($this->sock && $this->smtp_ok())) { $this->log_write("Warning: Cannot connect to mx host ".$host."\n"); $this->log_write("Error: ".$errstr." (".$errno.")\n"); continue; } $this->log_write("Connected to mx host ".$host."\n"); return TRUE; } $this->log_write("Error: Cannot connect to any mx hosts (".implode(", ", $MXHOSTS).")\n"); return FALSE; } function smtp_message($header, $body) { fputs($this->sock, $header."\r\n".$body); $this->smtp_debug("> ".str_replace("\r\n", "\n"."> ", $header."\n> ".$body."\n> ")); return TRUE; } function smtp_eom() { fputs($this->sock, "\r\n.\r\n"); $this->smtp_debug(". [EOM]\n"); return $this->smtp_ok(); } function smtp_ok() { $response = str_replace("\r\n", "", fgets($this->sock, 512)); $this->smtp_debug($response."\n"); if (!ereg("^[23]", $response)) { fputs($this->sock, "QUIT\r\n"); fgets($this->sock, 512); $this->log_write("Error: Remote host returned \"".$response."\"\n"); return FALSE; } return TRUE; } function smtp_putcmd($cmd, $arg = "") { if ($arg != "") { if($cmd=="") { $cmd = $arg; } else { $cmd = $cmd." ".$arg; } } fputs($this->sock, $cmd."\r\n"); $this->smtp_debug("> ".$cmd."\n"); return $this->smtp_ok(); } function smtp_error($string) { $this->log_write("Error: Error occurred while ".$string.".\n"); return FALSE; } function log_write($message) { $this->smtp_debug($message); if ($this->log_file == "") { return TRUE; } $message = date("M d H:i:s ").get_current_user()."[".getmypid()."]: ".$message; if (!@file_exists($this->log_file) || !($fp = @fopen($this->log_file, "a"))) { $this->smtp_debug("Warning: Cannot open log file \"".$this->log_file."\"\n"); return FALSE;; } flock($fp, LOCK_EX); fputs($fp, $message); fclose($fp); return TRUE; } function strip_comment($address) { $comment = "\([^()]*\)"; while (ereg($comment, $address)) { $address = ereg_replace($comment, "", $address); } return $address; } function get_address($address) { $address = ereg_replace("([ \t\r\n])+", "", $address); $address = ereg_replace("^.*<(.+)>.*$", "\1", $address); return $address; } function smtp_debug($message) { if ($this->debug) { //echo $message; } } } ?>
2021年01月24日
193 阅读
3 评论
4 点赞
2020-12-20
QQxml消息卡片生成源码
QQ XML消息自定义生成源码 这款源码是一个非常实用的 可以用来引流 可以让分享出来的普通网址变为卡片消息 比如自定义内容 有些友友们 好奇心 这样就可以增加大家的点击了下载地址:https://suxii.lanzous.com/iHtMVjjqfmb
2020年12月20日
421 阅读
1 评论
2 点赞
2020-12-20
typecho非常有特色的模块
强烈推荐:一款完全免费,而且功能十分强大的typecho模板演示地址(作者博客网站):https://ae.js.cn/下载链接奉上:点我下载
2020年12月20日
460 阅读
3 评论
5 点赞