记一次优化我的个人博客

前言

优化一下自己的博客访问速度等!不要求画面多么炫酷,但是,必须要快!快!!
我的博客:https://gmaya.top/欢迎访问哟!

效果

话不多说,先看效果
优化前:
优化前
优化后:
优化后

Hexo内部优化

我的个人博客站点使用hexo搭建,使用next模板。
模板配置文件搜索:motion
enable:是否开启页面动画,就是刚进来有没有那个慢吞吞的特效
async:是否开启异步加载,就是你的页面内容和特效是一起加载的。

Nginx优化访问

我的博客静态页面是通过Nginx代理的

修改worker_connections

默认是1024,相对而言扩大5倍,根据自己服务器决定

events {
    worker_connections  5024;
}

修改http配置

需要哪个就加上哪个

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;
	# 关闭日志
	access_log      off;
	# 隐藏响应头中的有关操作系统和web server(Nginx)版本号的信息,这样对于安全性是有好处的。
    server_tokens   off;
    sendfile        on;
	# 等数据包累计到一定大小发送,启用 sendfile 生效
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
	# 开启gzip
    gzip  on;
	# 启用gzip压缩的最小文件;小于设置值的文件将不会被压缩
    gzip_min_length 1k;
	# gzip 压缩级别 1-10
    gzip_comp_level 2;
	# 禁用IE 6 gzip
	gzip_disable "MSIE [1-6]\.";
	gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php;
	# 是否在http header中添加Vary: Accept-Encoding,建议开启
    gzip_vary on;

}

开启https访问

不喜欢网站一直显示不安全。
如果是http请求,将转发到https

    server {
        listen       80;
        server_name  gmaya.top;
        rewrite ^(.*)$ https://$host:443/$1 permanent;
    }

静态资源缓存

如果不是https,直接把内容加到80端口即可

    server {
        listen       443 ssl;
        server_name  gmaya.top;
		# 添加自己的证书
        ssl_certificate      xxx.crt;
        ssl_certificate_key  xxx.key;

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

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;
		
		location ~* \.(css|js|ico|gif|jpg|jpeg|png)$ {
			# 同上,通配所有以.css/.js/...结尾的请求 
			access_log off; 
			#忽略头部禁止缓存申明,类似与CDN的强制缓存功能
			proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
			# 开启缓存,时间864000秒,
			add_header Cache-Control "public,max-age=864000";
			root   C:\dev\blog;
            index  index.html index.htm;
		}
		location ~* \.(html|xml)$ {
            access_log off;
            # max-age<=0 时向server发送http请求确认 ,该资源是否有修改, 有的话 返回200 , 无的话 返回304。
            add_header Cache-Control no-cache;
			root   C:\dev\blog;
            index  index.html index.htm;
        }
	
        location / {
			access_log off;
            root   C:\dev\blog;
            index  index.html index.htm;
        }
	
    }

虽然一天到晚,总浏览量还不到20,哈哈。

发布了70 篇原创文章 · 获赞 30 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/gfl1427097103/article/details/105510963