如何代理将目录列表请求传递给另一台服务器(Nginx) [英] How to proxy pass a request for a directory listing to another server (Nginx)

查看:104
本文介绍了如何代理将目录列表请求传递给另一台服务器(Nginx)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在这里发布这个问题,作为对一个相当微妙的问题的回答.

I am just posting this here as an answer to a question I had for a fairly nuanced problem.

我有两台服务器(两台不同的机器):

I have two servers (two different machines):

backend.website.com
www.website.com

一些静态文件托管在名为 /audiofiles 的目录中,这些文件需要在 www.website.com/audiofiles 上访问,但存储在机器上用于backend.website.com.是的,这是一个复杂的要求,但在我们的情况下就是这种情况,无法更改.

Some static files are hosted in a directory called /audiofiles, these need to be accessible at www.website.com/audiofiles, but are stored on the machine for backend.website.com. Yes, this is a convoluted requirement, but it is the case in our situation and cannot be changed.

我在下面的回答是我们是如何做到这一点的.

My answer below is how we accomplished this.

推荐答案

这是让我们完成此任务的配置:

Here is the config that let us accomplish this:

backend.website.com:

server {
  listen 80;

  server_name backend.website.com;
  root /var/www/backend/;

  index index.html index.htm index.php;

  location ^~ /audiofiles/ {
    alias /some/other/folder/audiofiles/;
    autoindex on;
    break;
  }

  # ... other stuff
}

www.website.com

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name website.com www.website.com;

  location /audiofiles/ {
    proxy_pass         https://backend.website.com;
    proxy_redirect     /audiofiles/ https://www.website.com/audiofiles/;
    proxy_set_header   Host $proxy_host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
    proxy_set_header   X-NginX-Proxy true;
    proxy_set_header   X-Forwarded-Proto https;
  }
  
  # ... other stuff
}

这篇关于如何代理将目录列表请求传递给另一台服务器(Nginx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆