V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
fuhm
V2EX  ›  NGINX

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

  •  
  •   fuhm · 2015-04-02 21:02:56 +08:00 · 4604 次点击
    这是一个创建于 3313 天前的主题,其中的信息可能已经有所发展或是发生改变。
    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,何解?


    谢谢!
    12 条回复    2015-04-03 01:58:46 +08:00
    TONYHEAD
        1
    TONYHEAD  
       2015-04-02 21:13:15 +08:00   ❤️ 1
    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
        2
    fuhm  
    OP
       2015-04-02 21:22:59 +08:00
    @TONYHEAD 那为啥我这儿加上proxy_set_header Host \$host; 后就挂了?
    Slienc7
        3
    Slienc7  
       2015-04-02 21:27:37 +08:00
    如果只有单个域名用 sub_filter 就好了,免得麻烦....
    TONYHEAD
        4
    TONYHEAD  
       2015-04-02 21:34:12 +08:00
    @fuhm 你加 proxy_set_header Host sketchfab.com; 看看挂不挂……
    fuhm
        5
    fuhm  
    OP
       2015-04-02 21:42:42 +08:00
    @xgowex 替换不生效....
    fuhm
        6
    fuhm  
    OP
       2015-04-02 21:45:11 +08:00
    @TONYHEAD 恩,这下不挂了。
    但是sub_filter替换不生效是神马情况?
    fising
        7
    fising  
       2015-04-02 21:53:45 +08:00
    不生效是因为你没有安装官方自带的 http_sub_module
    编译的时候加上 --with-http_sub_module
    Slienc7
        8
    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
        9
    surftheair  
       2015-04-02 22:45:23 +08:00
    proxy_set_header Accept-Encoding "";
    你可能还需要替换css和js里的网址,还有外部链接,二级域名

    proxy_set_header 此处的host应该是被反代的网站,proxy_pass 后跟的是IP的话才需要手动指定,跟的是域名的话没必要指定。
    fuhm
        10
    fuhm  
    OP
       2015-04-02 23:55:17 +08:00
    @xgowex 关掉gzip也不行
    ryd994
        11
    ryd994  
       2015-04-03 01:57:57 +08:00
    @fuhm 不是关掉自己的gzip,而是避免来源gzip
    proxy_set_header Accept-Encoding "";
    ryd994
        12
    ryd994  
       2015-04-03 01:58:46 +08:00
    proxy_set_header Host \$host;
    为何$前加\ ?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3130 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 12:53 · PVG 20:53 · LAX 05:53 · JFK 08:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.