【问题标题】:Nginx in front of Tomcat not serving static filesTomcat前面的Nginx不提供静态文件
【发布时间】:2019-07-01 21:09:45
【问题描述】:

我在 Tomcat 前面有 Nginx,但没有提供 proxy_pass 静态文件。这是我的配置:

upstream tomcat {
server 127.0.0.1:8080 fail_timeout=0;
}

server {
    listen 80 ;
    listen [::]:80 ;
    index index.html index.htm index.nginx-debian.html;
    server_name example.com; # managed by Certbot   

    location / {
            try_files $uri $uri/ =404;
            proxy_pass http://127.0.0.1:8080/example/login;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Port $server_port;
    }

    location /css {
            root /var/lib/tomcat7/webapps/example/assets/theme/css/;
    }

如果我转到 https://example.com,我将获得没有 CSS、图像的 Tomcat 应用程序。

来自错误日志

2019/02/07 16:14:27 [error] 17098#17098: *3 open() "/var/lib/tomcat7    /webapps/example/example/assets/css/main.css" failed (2: No such file or directory), client: 192.168.1.2, server: example.com, request: "GET /example/assets/css/main.css HTTP/1.1", host: "example.com", referrer: "https://example.com/"

【问题讨论】:

    标签: nginx tomcat7 ubuntu-16.04


    【解决方案1】:

    我修复它:

    location /example/assets/css {
                root /var/lib/tomcat7/webapps/example/assets/css;
                proxy_pass http://127.0.0.1:8080/example/assets/css;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-02
      • 2018-10-23
      • 2021-12-02
      • 2020-09-14
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多