如何解决适用于js,css的NGINX缓存...具有用于Angular应用的proxy_pass
我想为我的Angular应用程序设置expires头文件,但仅针对静态文件,而不是除此之外的任何请求。
我正在与Angular通用(@ nestjs / universal)和nginx一起运行angular。 那就是我的Nginx配置:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
# SSL
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
# security
include nginxconfig.io/security.conf;
# additional config
include nginxconfig.io/general.conf;
# reverse proxy
location / {
proxy_pass http://localhost:3500;
include nginxconfig.io/proxy.conf;
}
}
# subdomains redirect
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name *.example.com;
# SSL
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
return 301 https://example.com$request_uri;
}
# HTTP redirect
server {
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name .example.com;
include nginxconfig.io/letsencrypt.conf;
location / {
return 301 https://example.com$request_uri;
}
}
我尝试了多段代码,但是似乎没有任何正常工作。像这样
...
# cache
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 365d;
}
...
然后我的文件出现404错误,并且页面无法正确加载:
Refused to apply style from 'https://example.com/styles.8b446047fbae0b4e9c57.css' because its MIME type ('text/html') is not a supported stylesheet MIME type,and strict MIME checking is enabled.
runtime-es2015.24fe51c614c9413ace4e.js:1
Failed to load resource: the server responded with a status of 404 ()
main-es2015.caa38f7ba189a68ea394.js:1
Failed to load resource: the server responded with a status of 404 ()
logo.png:1
Failed to load resource: the server responded with a status of 404 ()
...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。