nginx 反向代理 github 的配置文件,无法代理,求大神支招

2015-03-31 22:21:41 +08:00
 402645707

最近寡妇王的娘又开始来大姨妈了,Github也被扫地出门了,这是准备建世界互联网特区的节奏,
不多说了,饭要吃,墙要翻,Github要上,只能自建反代(以备万一哪天把SS等一大堆全封了)
————————————
server {
listen 80;
server_name inds.mrsang.pw;
rewrite ^(.*) https://inds.mrsang.pw$1 permanent;
}
server
{
listen 443;
server_name inds.mrsang.pw;
ssl on;
ssl_certificate /home/ca/ca.crt;
ssl_certificate_key /home/ca/ca.key;
location / {
proxy_redirect http://github.com/ /;
proxy_cookie_domain github.com inds.mrsang.pw;
proxy_pass http://192.30.252.130;
sub_filter github.com inds.mrsang.pw;
sub_filter_once off;
}
}
——————————
打开inds.mrsang.pw为空白,有人知道怎么改吗

6411 次点击
所在节点    问与答
20 条回复
Slienc7
2015-03-31 22:26:56 +08:00
樓主滿拼的,其實可以嘗試SNI Proxy,請搜社區


proxy_pass http://192.30.252.130;
好像不能這麽用,應該是https://域名,因爲有證書問題
proxy_redirect http://github.com/ /;
好像也不能這樣用,不是很確定

建議樓主去谷歌一份可以用的反代配置文件,然後照葫蘆畫瓢來改
Slienc7
2015-03-31 22:27:55 +08:00
1、nginx -t 是否報錯
2、空白頁面 狀態碼是多少
402645707
2015-03-31 22:32:28 +08:00
错误代码:DNS_PROBE_FINISHED_NXDOMAIN
service nginx configtest
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
402645707
2015-03-31 22:32:44 +08:00
Slienc7
2015-03-31 22:38:00 +08:00
DNS 查詢失敗,因此找不到位於 xxx.com 的伺服器。DNS 是將網站名稱轉譯成網際網路位址的網路服務。這項錯誤最常見的原因是沒有連線至網際網路或網路設定錯誤;也可能是因為 DNS 伺服器沒有回應,或是防火牆禁止 Google Chrome 存取網路。
...
錯誤代碼:DNS_PROBE_FINISHED_BAD_CONFIG

這是DNS沒解析好
402645707
2015-03-31 22:41:20 +08:00
@xgowex 好吧是我脑残了,忘了去dnspod里设置解析
surftheair
2015-03-31 22:46:57 +08:00
proxy_pass 不应该直接是IP,而应该是域名,或者手动指定hostname
402645707
2015-03-31 22:47:22 +08:00
@xgowex 新问题来了,访问https://inds.mrsang.pw提示证书出错,瞄了一下证书,是github的,ip也是我配置的,于是就点了信任,于是神奇的事情发生了,我费了这么大力气写了一个301跳转!!
402645707
2015-03-31 22:49:26 +08:00
@surftheair 跟着google的反代改的,我改改看
Slienc7
2015-03-31 22:49:34 +08:00
@402645707 不要重複造輪子了 谷歌/Github里一大堆直接可以用的nginx.conf,拿來刪刪改改就OK了
surftheair
2015-03-31 22:49:54 +08:00
另外反代一个网站不只是改下首页的域名这么简单,还有许多网页中的内容需要替换,还涉及二级域名,目录
Slienc7
2015-03-31 22:52:17 +08:00
@402645707 你這是改錯了... ... 還有就是各個網站機制不太一樣,不能全套
surftheair
2015-03-31 22:53:00 +08:00
@402645707 proxy_redirect httpS://github.com/ /;
surftheair
2015-03-31 22:55:21 +08:00
@surftheair 上面错了,看了下返回的header,被301到https://www.github.com/了,所以应该是proxy_redirect https://www.github.com/ /;
402645707
2015-03-31 22:59:45 +08:00
此网页包含重定向循环
错误代码:ERR_TOO_MANY_REDIRECTS
@surftheair 这可以理解为两套ssl死循环吗?
402645707
2015-03-31 23:00:34 +08:00
@surftheair
附代码
server
{
listen 443;
server_name inds.mrsang.pw;
ssl on;
ssl_certificate /home/ca/ca.crt;
ssl_certificate_key /home/ca/ca.key;
location / {
proxy_redirect https://www.github.com/ /;
proxy_cookie_domain www.github.com inds.mrsang.pw;
proxy_pass http://www.github.com;
sub_filter www.github.com inds.mrsang.pw;
sub_filter_once off;
}
}

server {
listen 80;
server_name inds.mrsang.pw;
rewrite ^(.*) https://inds.mrsang.pw$1 permanent;
}
surftheair
2015-03-31 23:01:40 +08:00
surftheair
2015-03-31 23:03:17 +08:00
@surftheair 我没有搜过,不知道有没有,建议还是找找网上现成的配置。你等会还会遇到很多小细节的东西,要完美地反代,配置文件会很长很长
402645707
2015-03-31 23:13:17 +08:00
@surftheair 表示只能坐等的节奏了
接触linux刚刚6个月(学生党自建ss,各种折腾)
接触nginx五天(自建blog,折腾反代)
经验根本不够啊
surftheair
2015-03-31 23:19:12 +08:00
@402645707 看你还在无限循环redirect。https://www.github.com会被github 301到http://github.com,但是又被你强行改成301到https://inds.mrsang.pw,而https://inds.mrsang.pw又是proxy_pass https://www.github.com,所以就会一直循环下去了。

解决办法就是proxy_pass https://github.com/;

这是我以前写的反代Google的配置: http://www.v2ex.com/t/137004#reply29

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/180687

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX