nginx - NGINX - 缓存静态(CSS / JS)文件后出现404错误
问题描述
我正在尝试设置 nginx 来缓存我的静态文件,例如 jpg、jpeg、css 和 js。
以下是我的 nginx.conf(不是 nginx.conf.default)的样子
events {}
http {
server {
listen 3000;
# listen 443 ssl;
server_name localhost;
# Set the SSL header only for HTTPS requests.
if ($scheme = "https") {
set $ssl_header SSL;
}
error_page 401 = @error401;
client_max_body_size 1000M;
# Expire rules for static content
location / {
# HTTPS header.
proxy_set_header X-Proto $ssl_header;
proxy_set_header Host $host;
proxy_set_header Client-IP $remote_addr;
# Redirection host.
proxy_pass http://localhost:300x;
}
location ~* .(jpg|jpeg|css|js)$ {
expires 1d;
access_log off;
add_header Cache-Control "public";
}
然后我尝试将以下内容添加到缓存中:
location ~* .(jpg|jpeg|css|js)$ {
expires 1d;
access_log off;
add_header Cache-Control "public";
}
我的所有 CSS 和 JS 文件都出现 404 错误。我的 JPG 和 JPEG 文件被缓存。我已经厌倦了在此处添加根目录和 in location \ {} 块。这似乎没有什么不同。
我尝试了许多不同的配置 - 我只想知道如何缓存我的 css 和 js 文件!
供参考:这是我的 nginx.conf.default 文件中的位置块:
location / {
root html;
index index.html index.htm;
}
我试过在服务器块中添加根,没有运气
解决方案
推荐阅读
- reactjs - 反应路由器不工作无法获取/关于
- r - 如何在 R 中对这些预测数据和实验数据进行分组?
- spring-mvc - 如何直接从keycloak访问spring boot应用程序?
- c++ - 如何在类中编写优化的构造函数 >
- javascript - 捕捉视图上的整数值变化
- python - 我如何在 Django 中运行这个过滤器?
- android - 传递稍后(不跟随)片段所需数据的最佳方式?
- azure-active-directory - Azure App Svc 中 Blazor 应用的 Azure AD 应用服务授权
- azure-log-analytics - 无法使用 Azure Monitor 日志运行查询“AzureActivity”
- r - R,使用for循环,如何根据不同的目标数据框生成具有不同结果的新变量