gpt4 book ai didi

ssl - http -> https 后 nginx 没有找到静态内容

转载 作者:太空宇宙 更新时间:2023-11-03 14:31:57 24 4
gpt4 key购买 nike

我有一个使用 http 的 nginx 静态文件服务的工作设置。

后来,当我切换到 https,将端口从 80 更改为 443 并添加 ssl 证书和 key 时,Web 服务器再也找不到静态文件了。我收到所有静态文件的 404 响应。这是我的 nginx 配置文件:

http {

include /etc/nginx/mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;


ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;


access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

upstream http_backend {
server 127.0.0.1:3001;
keepalive 32;
}

server {
listen 80;
server_name test.com;

# Redirect to https
location / {
rewrite ^ https://$host$request_uri permanent;
}
}

server {
listen 443 default_server ssl;
server_name localhost;
root /var/www/myblog/app/resources/public;

ssl on;
ssl_certificate /etc/nginx/certificate.crt;
ssl_certificate_key /etc/nginx/key.pem;

location / {
proxy_redirect off;

proxy_pass http://http_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto https;

access_log /var/www/logs/myblog.access.log;
error_log /var/www/logs/myblog.error.log;
}

location ^~ /(css|js) {
root /var/www/myblog/app/resources/public;
}
}
}

我的访问日志:

37.201.226.254 - - [26/Aug/2018:06:41:25 +0000] "GET /js/compiled/foo.js HTTP/1.1" 404 38 "https://www.test.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"    
37.201.226.254 - - [26/Aug/2018:06:41:25 +0000] "GET /css/mui.css HTTP/1.1" 404 38 "https://www.test.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"
37.201.226.254 - - [26/Aug/2018:06:41:25 +0000] "GET /css/style.css HTTP/1.1" 304 0 "https://www.test.com/" "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0"

文件位于 /var/www/myblog/app/resources/public 中:这被配置为 root。我从 /var/www/myblog/app 运行网络服务器。

请记住,这是我第一次使用 NGINX 进行部署。有谁知道我忘记配置什么来使用 https 提供静态文件?我的操作系统是 linux。

最佳答案

我通过随机试验和错误发现了问题。出于某种原因,改变

        location ^~ /(css|js) {
root /var/www/myblog/app/resources/public;
}

        location ~ ^/(css/|js/) {
root /var/www/myblog/app/resources/public/;
}

似乎有效。

关于ssl - http -> https 后 nginx 没有找到静态内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52023980/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com