傅令江的光影色彩世界
留住记忆的点滴
  • 首页
  • 文学
    • 诗词鉴赏
    • 美文共读
    • 原创
  • 编程
    • php
    • asp
    • .net
    • VB
    • C/C++
    • 易语言
    • js
    • 其他
    • 逆向
  • 运维
    • windows
    • linux
  • 光影色彩
    • 电影
    • 音乐
  • 科技
    • 互联网
    • 手机
  • 生活
    • 情感
  • 微语
5月52022

nginx任意反向代理配置(支持github,ip138,google) 这个是纯NGINX的任意反向代理

作者:傅令江   发布:2022-5-5 15:32   分类:linux   阅读:2965次   评论:0条  
  1. server {
  2. listen 80;
  3. server_name localhost; #改成自己的域名
  4. root "/home/wwwroot/default"; #改自己的服务器目录
  5. set $custom_PATH /HostLocMJJ;
  6. set $custom_host "https://www.baidu.com";
  7. set $custom_host3 "/";
  8. set $custom_host5 "/";
  9. if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) {
  10. set $custom_host $2;
  11.  
  12. set $custom_host3 $7;
  13. }
  14.  
  15. if ($custom_host3 = ""){
  16. set $custom_host3 "/";
  17. }
  18. if ($custom_host3 = " "){
  19. set $custom_host3 "/";
  20. }
  21. if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.+)\?(.+)$) {
  22. set $custom_host3 $7;
  23. }
  24. if ($request_uri ~* ^\/(.+)\/((http|https)://)((www.)?(\w+(\.)?)+)$) {
  25. return 301 $custom_PATH/$custom_host/;
  26. }
  27. set $custom_host2 "www.baidu.com";
  28.  
  29.  
  30. if ($custom_host ~* ^((http|https)://)((www.)?([\w-]+(\.)?)+)$) {
  31. set $custom_host2 $3;
  32. set $custom_host5 $1;
  33. }
  34. set $referer $custom_host;
  35. if ($http_referer ~* ^((http|https)://)(.*?)\/(.+)\/((http|https)://)(.*?)$) {
  36. set $referer $5$7;
  37.  
  38. }
  39. set $current "http://";
  40. if ($scheme = https) {
  41. set $current "https://";
  42. }
  43. proxy_hide_header content-security-policy;
  44.  
  45.  
  46.  
  47. location /HostLocMJJ/ {
  48. # proxy_connect_timeout 100s;
  49. # add_header Content-Security-Policy "default-src 'self' https://$host http://$host 'unsafe-inline' 'unsafe-eval' blob: data: ;";
  50. # proxy_set_header x-forwarded-for $remote_addr;
  51. # proxy_set_header X-Real-IP $remote_addr;
  52. # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  53. set $ishttp "http";
  54. if ($custom_host5 = https://) {
  55. set $ishttp "https";
  56. }
  57. proxy_ssl_server_name on;
  58. proxy_set_header X-Forwarded-Proto $ishttp;
  59. proxy_set_header Host $custom_host2;
  60. proxy_cache_key $host$uri$is_args$args;
  61. proxy_headers_hash_max_size 512;
  62. proxy_pass_header Server;
  63. proxy_headers_hash_bucket_size 128;
  64. proxy_buffer_size 64k;
  65. proxy_buffers 32 64k;
  66. proxy_busy_buffers_size 128k;
  67. proxy_set_header Cookie $http_cookie;
  68. proxy_cache_methods GET;
  69. proxy_cache_methods POST;
  70. proxy_cache_methods HEAD;
  71. proxy_redirect $upstream_http_location "$current$host$custom_PATH/$upstream_http_location";
  72. proxy_set_header Referer $referer;
  73. proxy_set_header User-Agent $http_user_agent;
  74. # 防止谷歌返回压缩的内容,因为压缩的内容无法替换字符串
  75. proxy_set_header Accept-Encoding "";
  76. proxy_connect_timeout 15000;
  77. proxy_send_timeout 15000;
  78. proxy_read_timeout 15000;
  79. proxy_cache_valid 200 304 301 1s;
  80. add_header MJJCDN-Cache "$upstream_cache_status";
  81. # proxy_temp_file_write_size 512000k;
  82. resolver 1.1.1.1; #改为自己想要的DNS
  83. proxy_set_header Accept-Encoding "";
  84. sub_filter_types text/plain text/javascript text/xml text/css application/x-javascript application/xml;
  85.  
  86. sub_filter_once off;
  87. proxy_temp_file_write_size 512000k;
  88. sub_filter "url(http" "url($current$host$custom_PATH/http";
  89. sub_filter "<head" '<base href="$current$host$custom_PATH/$custom_host/" /><head';
  90. sub_filter '\'https://' '\'$current$host$custom_PATH/https://';
  91. sub_filter '\'http://' '\'$current$host$custom_PATH/https://';
  92. sub_filter '\"https://' '\"$current$host$custom_PATH/https://';
  93. sub_filter '\"http://' '\"$current$host$custom_PATH/https://';
  94. sub_filter "=\"//" '="$current$host$custom_PATH/https://';
  95. sub_filter '="/' '="$current$host$custom_PATH/$custom_host/';
  96. sub_filter "='//" "='$current$host$custom_PATH/https://";
  97. sub_filter "='/" "='$current$host$custom_PATH/$custom_host/";
  98. sub_filter '="/search' '"search';
  99.  
  100.  
  101. sub_filter '"/images' '"images';
  102. sub_filter ', /images' ', images';
  103. sub_filter 'integrity' ', kkkk';
  104. sub_filter '../' '$current$host$custom_PATH/$custom_host/../';
  105. sub_filter "'http://$custom_host2" "'$current$host$custom_PATH/$custom_host";
  106. sub_filter "'https://$custom_host2" "'$current$host$custom_PATH/$custom_host";
  107. sub_filter "\"http://$custom_host2" "\"$current$host$custom_PATH/$custom_host";
  108. sub_filter "\"https://$custom_host2" "\"$current$host$custom_PATH/$custom_host";
  109. if ($request_uri ~* ^\/(.+)\/((http|https)://(www.)?([\w-]+(\.)?)+)(.*?)$) {
  110. proxy_pass $custom_host$7$is_args$query_string;
  111. }
  112.  
  113.  
  114. # # set $request_uri "qqqq";
  115. # add_header Content-Type "text/plain;charset=utf-8";
  116. # return 200 "Your IP Address:$referer</br>$http_referer";
  117. }
  118.  
  119. location / {
  120. add_header Content-Type "text/plain;charset=utf-8";
  121. return 200 "这是个正经网站";
  122. }
  123.  
  124.  
  125. }



本文固定链接: https://www.fulingjiang.cn/linux/237.html

blogger
该日志由 傅令江 于2022-5-5 15:32 Thursday发表在 linux 分类下。
版权所有:《傅令江的光影色彩世界》 → 《nginx任意反向代理配置(支持github,ip138,google) 这个是纯NGINX的任意反向代理》;
除特别标注,本博客所有文章均为原创. 互联分享,尊重版权,转载请以链接形式标明本文地址;
本文标签:
上一篇::wget 读取file中的url 批量下载
下一篇:Nginx 反向代理任意请求的域名

热门文章

  • 兄弟二周年祭

相关文章

  • 使用squid搭建http和https的代理服务器设置指南
  • MooseFS维护技巧集锦
  • CENTOS 6.3 OOMing (running out of memory) 问题解决
  • CC攻击原理及防范新思路
  • 为你宝塔面板一键开启HTTPS登陆+自动续期(面板+站点)
取消回复

发表评论

亲,头像对么?

提交中,请稍候……


木有头像就木JJ啦!还木有头像吗?点这里申请属于你的个性Gravatar头像吧!


  • 日历

  • 存档

    • 2024年10月(1)
    • 2023年2月(1)
    • 2022年11月(1)
    • 2022年10月(10)
    • 2022年9月(13)
    • 2022年8月(2)
    • 2022年7月(14)
    • 2022年6月(2)
    • 2022年5月(8)
    • 2022年4月(7)
    • 2022年3月(13)
    • 2022年2月(2)
    • 2022年1月(9)
    • 2021年12月(2)
    • 2021年11月(4)
    • 2021年10月(2)
    • 2021年9月(6)
    • 2021年7月(4)
    • 2021年6月(3)
    • 2021年5月(3)
    • 2021年4月(11)
    • 2021年3月(13)
    • 2021年2月(2)
    • 2021年1月(1)
    • 2020年12月(1)
    • 2020年4月(5)
    • 2019年9月(1)
    • 2019年8月(1)
    • 2019年5月(3)
    • 2018年3月(1)
    • 2017年10月(1)
    • 2016年7月(1)
    • 2016年4月(1)
    • 2015年12月(1)
    • 2015年11月(3)
    • 2015年9月(1)
    • 2015年8月(10)
    • 2015年7月(1)
    • 2015年6月(1)
    • 2015年4月(1)
    • 2015年3月(3)
    • 2015年2月(8)
    • 2015年1月(4)
    • 2014年12月(1)
    • 2014年11月(27)
    • 2014年10月(13)
    • 2014年9月(14)
    • 2014年8月(26)
    • 2014年7月(21)
  • 最新评论

    • 令狐江:
      喜欢这首歌是因为可以引起共鸣!
  • 链接

    • 演讲稿网
    • Recollect
    • 演讲稿
    • 祁阳人生活网
    • 我爱演讲稿网
  • 搜索

  • 标签

      函数 自定义方法 SEO 分页 分页函数 分页方法 nginx重新的一些规则
  • 分类

    • 文学(0)
    • 编程(0)
    • 运维(0)
    • 光影色彩(0)
    • 科技(0)
    • 生活(0)
    • 诗词鉴赏(3)
    • 美文共读(1)
    • 原创(10)
    • php(111)
    • asp(1)
    • .net(0)
    • VB(0)
    • C/C++(0)
    • 易语言(0)
    • js(8)
    • 其他(9)
    • 逆向(2)
    • windows(11)
    • linux(121)
    • 电影(0)
    • 音乐(1)
    • 互联网(4)
    • 手机(0)
    • 情感(2)
  • 最新文章热门文章随机文章

    • 兄弟二周年祭
    • openai给的ionCube 解密代码,应该是老版本可以这样
    • WordPress – 5秒盾防CC(PHP通用代码)
    • 我高中最好的朋友今天猝死了-伤心得不行
    • Linux系统中 systemd-journaldCPU占用异常的解决方法
    • SVN Skipped 'xxx' -- Node remains in conflict 错误的解决办法
    • 解决Linux读写nfs共享盘速度慢的问题
    • php 获取302跳转后的地址
    • 让vsftp显示隐藏文件的办法,比如显示 .htaccess
    • Nginx负载均衡配置实例详解
    • PHP加密文件破解代码
    • php采集用获取链接的正则
    • php文章相似度计算 不用similar_text()函数
    • eval(gzinflate(base64_decode N层,自动解密
    • PHP base64+gzinflate压缩加密和解密算法
Copyright © 2001-2025 傅令江的光影色彩世界. Powered by www.fulingjiang.cn ICP备案:京ICP备14015190号-5