我在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应用程序。
从error.log
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/"
答案 0 :(得分:0)
我用以下方法修复它:
location /example/assets/css {
root /var/lib/tomcat7/webapps/example/assets/css;
proxy_pass http://127.0.0.1:8080/example/assets/css;
}