宝塔反代加统计代码
先用宝塔手动做好反代 然后在三个位置加入以三句代码即可 proxy_set_header Accept-Encoding ""; sub_filter '</head>' '</head><script language="javascript"src="http://www.baidu.com/tj/tj.js"></script>'; sub_filter_once off;(可以改成on因为只替换一次即可)
server
{
listen 80;
server_name baidu.lostangel.cn;
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/baidu.lostangel.cn;
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
error_page 404 /404.html;
error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置,可以注释或修改
#PROXY-START
location ~ /purge(/.*) {
proxy_cache_purge cache_one www.baidu.com$request_uri$is_args$args;
#access_log /www/wwwlogs/baidu.lostangel.cn_purge_cache.log;
}
location /
{
proxy_pass http://www.baidu.com;
proxy_set_header Host www.baidu.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;
#持久化连接相关配置
#proxy_connect_timeout 30s;
#proxy_read_timeout 86400s;
#proxy_send_timeout 30s;
#proxy_http_version 1.1;
#proxy_set_header Upgrade $http_upgrade;
#proxy_set_header Connection "upgrade";
add_header X-Cache $upstream_cache_status;
proxy_set_header Accept-Encoding "";
sub_filter '</head>' '</head><script language="javascript"src="http://www.baidu.com/tj/tj.js"></script>';
sub_filter_once off;
expires 12h;
}
location ~ .*\.(php|jsp|cgi|asp|aspx|flv|swf|xml)?$
{
proxy_set_header Host www.baidu.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;
proxy_pass http://www.baidu.com;
proxy_set_header Accept-Encoding "";
sub_filter '</head>' '</head><script language="javascript"src="http://www.baidu.com/tj/tj.js"></script>';
sub_filter_once off;
}
location ~ .*\.(html|htm|png|gif|jpeg|jpg|bmp|js|css)?$
{
proxy_set_header Host www.baidu.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;
proxy_pass http://www.baidu.com;
#缓存相关配置
#proxy_cache cache_one;
#proxy_cache_key $host$request_uri$is_args$args;
#proxy_cache_valid 200 304 301 302 1h;
proxy_set_header Accept-Encoding "";
sub_filter '</head>' '</head><script language="javascript"src="http://www.baidu.com/tj/tj.js"></script>';
sub_filter_once off;
expires 24h;
}
#PROXY-END
include enable-php-70.conf;
#PHP-INFO-END
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/baidu.lostangel.cn.conf;
#REWRITE-END
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一键申请SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}
access_log /www/wwwlogs/baidu.lostangel.cn.log;
error_log /www/wwwlogs/baidu.lostangel.cn.error.log;
}
网友评论