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

用 Nginx 反向代理 Office Web App 遇到了问题

  •  
  •   RockyLee · 2015-03-24 16:10:40 +08:00 · 3384 次点击
    这是一个创建于 3314 天前的主题,其中的信息可能已经有所发展或是发生改变。

    微软的 Office Web App 可以直接在线预览 office 文档。效果如 http://www.labnol.org/internet/google-docs-viewer-alternative/26591/

    我需要在自己的网站中以 iframe 的形式嵌入页面中,并可以操作 iframe 中的元素,于是想到可以用反代 Office Web App 来解决跨域问题。

    在用 Nginx 反代过程中遇到了一些问题。

    Nginx 配置如下

    location /document {
        proxy_pass https://view.officeapps.live.com;
        proxy_set_header host              $http_host;
        proxy_set_header X-real-IP         $remote_addr;
        proxy_set_header X-forwarded-for   $proxy_add_x_forwded_for; 
    }
    

    问题如下:

    1. 访问 my.domain.com/document,页面错误内容为:
      404-File or directory not found.(IIS)

    2. 访问 my.domain.com/document/op/view.aspx?src=http://img.labnol.org/di/Word.docx 页面错误内容为:
      404 NOT Found(Nginx/1.6.2),并且请求被重定向到my.domain.com/error/error.html?aspxerrorpath=/document/op/view/aspx

    Nginx 用的不多,试了好久都没有找到原因,请大家指点一下。

    4 条回复    2015-03-25 09:53:11 +08:00
    takatost
        1
    takatost  
       2015-03-24 19:07:32 +08:00 via iPhone   ❤️ 1
    document 也带在后面了,最好用二级域名,简单暴力
    RockyLee
        2
    RockyLee  
    OP
       2015-03-24 20:53:47 +08:00
    @takatost 嗯,公司的原因,不能用这个方法。
    takatost
        3
    takatost  
       2015-03-25 06:57:39 +08:00 via iPhone   ❤️ 1
    proxy_pass 后面的域名最后带上斜杠
    RockyLee
        4
    RockyLee  
    OP
       2015-03-25 09:53:11 +08:00
    @takatost It works! Thx!!! ヾ(・ω・*)ノ
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1013 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 18:49 · PVG 02:49 · LAX 11:49 · JFK 14:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.