首页
关于我们
友链链接
壁纸下载
更多
统计中心
热点搜索
图床上传
Search
1
[Win DD包] wes7-x86-cn-精简,安装后仅占用1.55G存储空间
25,458 阅读
2
保姆级教程!甲骨文ARM DD成Debian10并升级内核成5.10
6,174 阅读
3
N1教程:Openwrt安装docker webui界面(基于flippy openwrt n1固件)
5,195 阅读
4
ZFAKA小店Docker版之 数据的备份和迁移
5,000 阅读
5
甲骨文oracle ARM 重装 Debian 10
4,676 阅读
Linux学堂
网站建设
网络资源
主题插件
固件工具
主机评测
登录
Search
标签搜索
vps
linux
bench
typecho
nginx
empirecms
lnmp
centos
cloudflare
openwrt
n1
google
301
qbittorrent
ssl
rclone
onedrive
mysql
storage
ssh
V+变量
累计撰写
210
篇文章
累计收到
91
条评论
首页
栏目
Linux学堂
网站建设
网络资源
主题插件
固件工具
主机评测
页面
关于我们
友链链接
壁纸下载
统计中心
热点搜索
图床上传
搜索到
10
篇与
的结果
2025-01-19
Nginx常用的301重定向规则
仅适用于Nginx, Apache请移步: Apache .htaccess 301重定向规则大全,赶紧收藏吧注意: 所有代码作用范围都在server配置区域中:server { #Rewrite Rules }不带www重定向带有wwwif ($http_host !~ "^www.towait.com$") { rewrite ^(.*) http://www.towait.com$1 permanent; }或if ($host !~* ^www\.) { rewrite ^(.*)$ $scheme://www.$host$1 permanent; }带有www重定向不带wwwif ($http_host !~ "^towait.com$") { rewrite ^(.*) http://towait.com$1 permanent; }域名a.com重定向b.comif ($http_host ~ "^a.com$") { rewrite ^(.*) http://b.com$1 permanent; }强制HTTPS访问1在服务端配置SSL的情况if ($scheme != "https") { return 301 https://$host$request_uri; }2在CDN端配置SSL证书的情况if ($http_x_forwarded_proto = "http") { return 301 https://$server_name$request_uri; }
2025年01月19日
11 阅读
1 评论
0 点赞
2025-01-19
解决Nginx中强制跳转HTTPS访问出现的太多重定向错误
因为可以白嫖HTTPS服务,所以目前很多项目都部署在cloudflare的CDN中,此前都用的自己服务端的SSL证书,今天在cloudflare申请了一年的免费证书,在做URL统一化的时候(强制www和https访问)发现重定向次数过多的错误(redirected you too many times),这是由于我未在服务端配置SSL证书,也就是说cloudflare以HTTP回源,所以服务器接收到的信息就是HTTP请求,但是受强制HTTPS访问规则影响,服务端又给它重定向到HTTPS,又回到了CDN那边,结果CDN又产生HTTP回源请求,这就形成了一个闭环,听上去有点绕,总之访问页面就这么来回无限循环了。此前在服务端配置了SSL并强制用HTTPS访问的nginx规则是if ($scheme != "https") { return 301 https://$host$request_uri; }现在如果我们未在服务端配置SSL使用CDN端的SSL证书并启用HTTPS访问的正确写法是if ($http_x_forwarded_proto = "http") { return 301 https://$server_name$request_uri; }
2025年01月19日
15 阅读
0 评论
0 点赞
2024-12-24
Nginx反代Cloudflare源站的两种写法
最近在折腾nginx反代的问题,由于网站服务器在国外,给套了一层cf,直接用反代源站的办法基本都是失败,没办法只能网上查找资料,加上自力更生,找到两种反代cf的写法。dns设置本文我们针对全面反代cloudflare来说,直接反代源站也是类似的操作,我们当前采取的是ns接入cloudflare的方式,即域名服务器已经修改成了cloudflare的服务器,在cloudflare上设置dns记录,添加两条记录。cf.example.com 解析到你的源站ip,并开启cdn(如果你是直接反代源站,那么这一步关闭cdn,仅作为dns使用即可)blog.example.com 解析到你的反代服务器ip,仅作为dns使用。1 利用proxy_ssl_name声明源站,告诉CF #PROXY-START/ location / { proxy_pass https://www.xboy.uk; proxy_set_header Host www.xboy.uk; #向后端传递访客 ip 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; #向后端传递访客 ip (反代CF增加规则) proxy_ssl_name www.xboy.uk; proxy_ssl_server_name on; #缓存设置 add_header X-Cache $upstream_cache_status; #Set Nginx Cache proxy_ignore_headers Set-Cookie Cache-Control expires; proxy_cache_key $host$uri$is_args$args; proxy_cache_valid 200 304 301 302 120m; expires 12h; } #PROXY-END/2 反代到cloudflare IP# 如果反代的是cloudflare location / { # 由于我们反代的cloudflare使用的是 https,所以我们需要指明sni,不然是无法握手的,另外还需要设置host,这两个都要设置成接入cloudflare的域名。 proxy_ssl_name cdn.example.com; proxy_ssl_server_name on; proxy_set_header Host cdn.example.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect off; # 重点!由于我们接入cloudflare的域名和我们反代服务器的域名不一样,typecho的数据库里面记录的链接都是cdn.example.com的形式,所以我们要做内容替换。我们还需要通过设置Accept-Encoding "";来告诉服务器不要对内容进行压缩,不然返回的数据没办法使用sub_filter替换。 proxy_set_header Accept-Encoding ""; sub_filter "https://cdn.example.com" "https://blog.example.com"; # 开启内容多次替换 sub_filter_once off; # 禁用缓存 (这个应该会影响到cloudfalre的缓存,不建议设置) add_header Cache-Control no-cache; expires 12h; # 这里随便找个cloudflare的ip即可 proxy_pass https://1.0.0.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }
2024年12月24日
109 阅读
0 评论
0 点赞
2024-11-30
解决 nginx报错: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/xxx.com.conf:18
在 1.25.1 版本后的 nginx 运行日志中,可能会发现以下警告信息: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /usr/local/nginx/conf/vhost/xxx.com.conf:18原配置:listen 443 ssl http2;修改配置为:`listen 443 ssl;http2 on;`重启 nginx 即可。参考:https://github.com/nginxinc/kubernetes-ingress/issues/4237
2024年11月30日
31 阅读
0 评论
0 点赞
2024-11-29
Nginx反向代理教程
最近趁着黑五买了一个大盘鸡,但是直接访问速度很慢,于是决定利用快速访问的小鸡来反代比较好,网上找了半天,下面的代码好用。location / { proxy_pass https://www.xboy.uk:80; # 后端服务器的地址 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_set_header X-Forwarded-Proto $scheme; # 可选:处理WebSocket(如果需要) proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; # 可选:设置超时时间 proxy_read_timeout 60s; proxy_connect_timeout 60s; proxy_send_timeout 60s; }
2024年11月29日
44 阅读
17 评论
0 点赞
1
2