Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

这个搜索似乎在国内环境用不了 #30

Closed
huhaku opened this issue Oct 17, 2024 · 7 comments
Closed

这个搜索似乎在国内环境用不了 #30

huhaku opened this issue Oct 17, 2024 · 7 comments

Comments

@huhaku
Copy link

huhaku commented Oct 17, 2024

看了下,有不少资源是直接使用google的,在国内有墙环境下是用不了的.有很多时候翻墙并不是那么方便
感觉是不是可以在服务器上做下反代去处理掉这些资源

@KoriIku
Copy link
Owner

KoriIku commented Oct 17, 2024

可以考虑 whoogle 或者 searxng ,在反代Google方面这些项目更符合需求、也更成熟。

@KoriIku KoriIku pinned this issue Oct 17, 2024
@huhaku
Copy link
Author

huhaku commented Oct 19, 2024

我之前用的就是searxng,感觉太重了,想找一个轻量化的替代方案.
不过没事,反代的问题我自己解决了,用国外的服务器反代样式有点错位,并且好像会自动跳到TW站去,不过问题不大,调一下就好
感谢你提供了一个那么好的前端

@huhaku huhaku closed this as completed Oct 19, 2024
@KoriIku
Copy link
Owner

KoriIku commented Oct 19, 2024

我之前用的就是searxng,感觉太重了,想找一个轻量化的替代方案. 不过没事,反代的问题我自己解决了,用国外的服务器反代样式有点错位,并且好像会自动跳到TW站去,不过问题不大,调一下就好 感谢你提供了一个那么好的前端

如果您有时间,是否可以在此分享您的解决方案,此 issue 已置顶,您的分享会对之后有相似问题的朋友有所帮助。(o゚v゚)ノ

@huhaku
Copy link
Author

huhaku commented Oct 19, 2024

https://cse.google.com/cse.js?cx=%VITE_GOOGLE_CSE_CX%
替换为 /cse.js?cx=%VITE_GOOGLE_CSE_CX%

下面配置仅供参考

    listen       80;
    listen  [::]:80;
    server_name  localhost;

    access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        try_files $uri $uri/ /index.html;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    
    location ^~ /cse.js {
        proxy_pass https://cse.google.com;
    
        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;
    }

    location /api/play {
        proxy_pass https://play.google.com;
        
        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;
    }

    location /api/support {
        proxy_pass https://support.google.com;
        
        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;
    }

    location /api/csqr {
        proxy_pass https://csqr-autopush.corp.google.com;
        
        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;
    }

    location /api/csex {
        proxy_pass https://cse.google.com;
        
        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;
    }

    location /api/ads {
        proxy_pass https://www.adsensecustomsearchads.com;
        
        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;
    }

    location /api/developers {
        proxy_pass https://developers.google.com;
        
        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;
    }

    location /api/clients1 {
        proxy_pass https://clients1.google.com;
    
        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;
    }

    # 处理 /api 作为通用代理
    location /api {
        proxy_pass https://www.google.com;
        
        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;
    }

    sub_filter '+zh_TW' '+zh_CN';
    sub_filter '=zh-TW' '=zh-CN';    
    # 处理输出中的 URL 替换
    sub_filter 'https://cse.google.com' '/api';
    sub_filter 'www.google.com' '/api';
    sub_filter '//play.google.com' '/api/play';
    sub_filter '//support.google.com' '/api/support';
    sub_filter '//csqr-autopush.corp.google.com' '/api/csqr';
    sub_filter '//cse.google.com' '/api/csex';
    sub_filter '//www.adsensecustomsearchads.com' '/api/ads';
    sub_filter '//developers.google.com' '/api/developers';

    # 处理搜索api
    sub_filter 'clients1.' '';
    sub_filter 'a.vs' '"/api/clients1"';

    proxy_set_header Accept-Encoding "";
    sub_filter_types text/css application/javascript;
    sub_filter_once off;
}

@zhyueyueniao
Copy link

这个是直接进docker里用你这个覆盖nginx配置就行了吗

@huhaku
Copy link
Author

huhaku commented Nov 15, 2024

这个是直接进docker里用你这个覆盖nginx配置就行了吗

对,
不过不是直接覆盖,要根据你自己的需求调整

@hzqim
Copy link

hzqim commented Dec 3, 2024

这个是直接进docker里用你这个覆盖nginx配置就行了吗

对, 不过不是直接覆盖,要根据你自己的需求调整

请问还需要修改哪些设置才可以过到目的?
我用上述nginx配置,除把 localhost 换成我的域名之后不知道还要设置什么。部署后页面发现没有搜索框,F12打开控制台,提示https://我的域名/cse.js?cx=%VITE_GOOGLE_CSE_CX% 404 not found.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants