Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

Nginx 相关配置

模拟if多重判断

背景:因为有人恶意刷我们一个链接,拒掉这些访问

伪代码如下:

if ( $request ~ "/credit-user/reg-get-code"  && $http_user_agent ~ okhttp ) { 
    rewrite ^/(.*)$ https://www.iteblog.com/$1 permanent; 
    #return 403;
}

但可惜Nginx并不支持这种写法,只好用下面这种写法进行多重判断,经测试可用。

location / {
    proxy_pass  http://127.0.0.1:8080;
    set $flag 0;
    if ( $request ~ "/credit-user/reg-get-code" ) {
         set $flag "${flag}1";
       }
    if ( $http_user_agent ~ okhttp ) {
         set $flag "${flag}2";
       }
    if ( $flag = "012" ) {
        return 403;
    }
}

域名重定向

比如访问http://***.com/abc/api/jd/id=1指向http://***.com/api/jd/id=1

location ~^/abc/ {
    rewrite /abc/(.*) /$1 break;
}

配置 Vue history路由

1、根路径配置

server {
    listen              80;
    server_name         vue.xxx.com;

    location  / {
        index  index.html index.htm;
        root   /var/www/channelGift/;  #vue项目路径
        try_files $uri $uri/ /index.html;
    }
}

2、非根目录配置

server {
    listen              80;
    server_name         a.xxx.com;   #a域名

    location / {
        index  index.html index.htm;
        root   /var/www/a;    #a域名根目录
        error_page   500 502 503 504 /index.html;
    }
    location  ^~ /channelGift {
        alias  /var/www/b/;    #vue项目路径
        index  index.html;
        try_files $uri $uri/ /channelGift/index.html;   #不要用绝对路径,如 /var/www/channelGift/index.html
    }
}

还应该在VUE项目里把每个路径加上/channelGift这一段(或者指定base: '/channelGift/'),要不页面会显示为空白:

Vue路由基路径配置

访问时使用下面路径即可访问

http://a.xxx.com/channelGift/product-list.html?fcode=1a399819

开启js压缩

修改Nginx参数,开启gzip,压缩类型gzip_types中的application/x-javascript并不是代表javascript,真正代表javascript的是:application/javascript,所以还需要在gzip_types中添加进去。然后重启Nginx

http {
    gzip on;
    gzip_min_length 10k;
    gzip_comp_level 6;
    gzip_static on;
    gzip_types text/html text/plain application/x-javascript application/javascript text/css application/xml text/javascript  image/jpeg image/gif image/png;
}

测试:如果返回结果有Content-Encoding: gzip说明压缩成功

# curl -I -H "Accept-Encoding: gzip, deflate" "http://www.*****.com/css/chunk-vendors.728eb7d9.css"
HTTP/1.1 200 OK
Server: nginx/1.12.2
Date: Sat, 12 Oct 2019 09:54:39 GMT
Content-Type: text/css
Last-Modified: Fri, 11 Oct 2019 11:43:45 GMT
Connection: keep-alive
ETag: W/"5da06af1-39032"
Expires: Tue, 22 Oct 2019 09:54:39 GMT
Cache-Control: max-age=864000
Content-Encoding: gzip

或者在开发者控制台里查看,response headers 有内容Content-Encoding: gzip就是开启了gzip

没有开启gzip,则在request headers 里显示Accept-Encoding: gzip, deflate

上一篇 Linux下查看磁盘占用空间
下一篇 后端运维常见概念