小z博客大佬的一键Nginx安装包(适用于Centos 7、Deebian 8),执行下面的命令安装即可。
wget https://raw.githubusercontent.com/helloxz/nginx-cdn/master/nginx.sh
chmod +x nginx.sh && ./nginx.sh
#创建缓存目录
mkdir -p /data/wwwroot/caches/vps77
#设置缓存目录权限
chown -R www:www /data/wwwroot/caches/vps77
#创建nginx配置文件vps77.com.conf
vi /usr/local/nginx/conf/vhost/vps77.com.conf
输入i后,进入编辑模式
在里面添加下面的内容,缓存目录/缓存时间请根据实际情况调整,后面会详细说明各参数含义。
proxy_cache_path /data/wwwroot/caches/vps77 levels=1:2 keys_zone=vps77cache:192m max_size=2048m inactive=2h;
#proxy_temp_path /data/wwwroot/caches/temp;
upstream vps77cache {
server 注意这里改成你源站IP:443;
}
server {
listen 80;
listen 443 ssl http2;
ssl_certificate /usr/local/nginx/conf/ssl/vps77.com.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/vps77.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_timeout 10m;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_buffer_size 1400;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
server_name www.vps77.com;
if ($ssl_protocol = "") { return 301 https://$host$request_uri; }
if ($host != www.vps77.com) { return 301 $scheme://www.vps77.com$request_uri; }
location ~.*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
proxy_pass https://www.vps77.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_cache vps77cache;
proxy_cache_valid 200 302 2h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
expires 30d;
}
location / {
proxy_pass https://www.vps77.com;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
proxy_max_temp_file_size 0;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
location ~ /\.ht {
deny all;
}
}
1、/data/wwwroot/caches/vps77.com:为缓存目录
2、levels:指定该缓存空间有两层hash目录,第一层目录为1个字母,第二层为2个字母。
3、keys_zone=vps77:50m:为缓存空间起个名字,这里取名为“vps77”,后面的50m指内存缓存空间 。
4、inactive=30m:如果30分钟内该资源没有被访问则删除
5、max_size=50m:指硬盘缓存大小为50MB
6、proxy_cache_valid:指定状态码缓存时间,前面写状态码,后面写缓存时间。
最后别忘了重载nginx使配置生效,输入:/usr/local/nginx/sbin/nginx -s reload,如果有报错,根据报错信息排查。
WHMCS 使用反代后获取真实IP
添加到 configuration.php
$_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR']; // 获取真实IP
list($_SERVER['REMOTE_ADDR']) = explode(', ', $_SERVER['REMOTE_ADDR'], 2); // 可能通过多个代理,其中第一个为真实ip地址
$_SERVER['HTTP_X_FORWARDED_FOR'] = $_SERVER['REMOTE_ADDR']; // 添加到WHMCS IP变量