nginx 反向代理,部分链接依旧是原域名,求解

2015-04-02 21:02:56 +08:00
 fuhm
https://dl.isway.cn
需要反代的网站是https://sketchfab.com

所有的模型链接都是原域名,有没有解决办法?
代码如下:
server {
listen 443;
server_name dl.isway.cn;

ssl on;
ssl_certificate /root/nginx/ssl.crt;
ssl_certificate_key /root/nginx/ssl.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
ssl_prefer_server_ciphers on;

location / {
proxy_pass https://sketchfab.com/;
proxy_redirect off ;
proxy_cookie_domain sketchfab.com dl.isway.cn;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header REMOTE-HOST \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}

另外
proxy_set_header Host \$host;
加上去后,就访问不了-Bad Request,何解?


谢谢!
4619 次点击
所在节点    NGINX
12 条回复
TONYHEAD
2015-04-02 21:13:15 +08:00
subs_filter 'sketchfab.com/models/' 'dl.isway.cn/models/';

subs_filter挺好用的: https://code.google.com/p/substitutions4nginx/




proxy_set_header Host \$host; 意思是 proxy_set_header Host sketchfab.com;
fuhm
2015-04-02 21:22:59 +08:00
@TONYHEAD 那为啥我这儿加上proxy_set_header Host \$host; 后就挂了?
Slienc7
2015-04-02 21:27:37 +08:00
如果只有单个域名用 sub_filter 就好了,免得麻烦....
TONYHEAD
2015-04-02 21:34:12 +08:00
@fuhm 你加 proxy_set_header Host sketchfab.com; 看看挂不挂……
fuhm
2015-04-02 21:42:42 +08:00
@xgowex 替换不生效....
fuhm
2015-04-02 21:45:11 +08:00
@TONYHEAD 恩,这下不挂了。
但是sub_filter替换不生效是神马情况?
fising
2015-04-02 21:53:45 +08:00
不生效是因为你没有安装官方自带的 http_sub_module
编译的时候加上 --with-http_sub_module
Slienc7
2015-04-02 22:02:29 +08:00
@fising
It won't run wihout what you say.


@fuhm
Try to disable GZIP if it is enabled.
Remember to use nignx -t to check your conf file instead of restarting nginx directly.



shu ru fa gua le ,zhe shi shen me qing kuang. WTF...
surftheair
2015-04-02 22:45:23 +08:00
proxy_set_header Accept-Encoding "";
你可能还需要替换css和js里的网址,还有外部链接,二级域名

proxy_set_header 此处的host应该是被反代的网站,proxy_pass 后跟的是IP的话才需要手动指定,跟的是域名的话没必要指定。
fuhm
2015-04-02 23:55:17 +08:00
@xgowex 关掉gzip也不行
ryd994
2015-04-03 01:57:57 +08:00
@fuhm 不是关掉自己的gzip,而是避免来源gzip
proxy_set_header Accept-Encoding "";
ryd994
2015-04-03 01:58:46 +08:00
proxy_set_header Host \$host;
为何$前加\ ?

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

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

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

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

© 2021 V2EX