【问题标题】:nginx serve static files and run server on same hostnginx 提供静态文件并在同一主机上运行服务器
【发布时间】:2018-03-21 07:05:41
【问题描述】:

几乎可以按照我想要的方式工作 - 基本上我正在尝试在host/static 上提供静态文件(包括目录列表),并为任何非文件请求(包括默认站点)提供给另一个后端。下面的配置似乎可以做到这一点,但剩下的一个问题是我无法使用host/static 进入根静态目录 - 需要尾部斜杠!有什么想法吗?

我的配置:

location / {
  try_files /static/$uri /static/$uri/ @myserver;
}

location /static/ {
  alias /var/www/static_files/;
  autoindex on;
  disable_symlinks off;
}

location @myserver {
  proxy_pass              http://localhost:8081;
  proxy_set_header        Host $host;
  proxy_set_header        X-Real-IP $remote_addr;
  proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_connect_timeout   150;
  proxy_send_timeout      100;
  proxy_read_timeout      100;
  proxy_buffers           4 32k;
  client_max_body_size    8m;
  client_body_buffer_size 128k;
}

【问题讨论】:

  • 您是否尝试过从locationalias 语句中删除尾随/
  • @RichardSmith 哈,成功了!谢谢! (我希望这很简单!)

标签: nginx web config nginx-location nginx-reverse-proxy


【解决方案1】:

正如@RichardSmith 所说 - 要获得此行为,只需从 locationalias 语句中删除尾部斜杠即可。

【讨论】:

    猜你喜欢
    • 2021-07-19
    • 2016-05-23
    • 1970-01-01
    • 2010-12-01
    • 2014-07-25
    • 1970-01-01
    • 1970-01-01
    • 2020-02-21
    • 1970-01-01
    相关资源
    最近更新 更多