问题描述
我想为我的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;
}
...
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 (将#修改为@)