【问题标题】:Nginx URL Rewrite ProcessingNginx URL 重写处理
【发布时间】:2018-08-08 12:40:45
【问题描述】:

我有一个提供静态资产的 nginx 容器,如果它收到对

的请求

https://mysite:8090/static/2.1.1/test/mystyle.css(其中 2.1.1 可以是任何语义版本)

Nginx 应该服务于 /usr/share/nginx/html/test/mystyle.css 下的静态资源

我尝试了以下配置,但没有成功:

http {
    include    mime.types;
    sendfile on;
    server {
        server_name localhost default";
        rewrite ^.*/static/[^/]+/(.*)$ $1;
        location / {
          root /usr/share/nginx/html/;
        }
    }
}

【问题讨论】:

  • 这意味着当您访问http://localhost:8090/static/2.1.1/test/mystyle.css 时,CSS 工作正常,但使用mysite:8090 时,它不起作用。

标签: nginx nginx-reverse-proxy


【解决方案1】:

看起来我让这变得比需要的更复杂,没有意识到最初的斜线被删除了。

这对我有用:

rewrite ^/static/[^/]+/(.*)$ /$1 break;

【讨论】:

    猜你喜欢
    • 2014-02-01
    • 2019-09-27
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多