我的配置文件位于/etc/nginx/sites-enabled
名为songreccs.conf
并且看起来像这样:
server {
server_name www.songreccs.com songreccs.com;
location /static {
root /home/user/sonreccs/flaskrec/;
}
location / {
proxy_pass http://localhost:8000;
include /etc/nginx/proxy_params;
proxy_redirect off;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/songreccs.com/fullchain.pem; # manage>
ssl_certificate_key /etc/letsencrypt/live/songreccs.com/privkey.pem; # mana>
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
listen 80;
server_name www.songreccs.com songreccs.com;
if ($host = www.songreccs.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
return 404; # managed by Certbot
}
我认为这就是该文件正在做的事情:
第一个块监听端口 443,并将所有内容重定向到location /
块中指定的内容。应该location /static
给出在哪里找到静态文件的说明。
第二个块监听端口 80,并将所有进入的数据包重定向至端口 443。然后由第一个块再次处理该任务。
静态文件的路径位于home/user/sonreccs/flaskrec/static
。
我在网站上遇到的错误是:
[Error] Failed to load resource: the server responded with a status of 403 (Forbidden) (styles.css, line 0)
在使用 certbot 安装证书之前不会发生这种情况。我该如何更改它,以便再次允许它?
答案1
尝试以下 Nginx 配置:
server {
listen 443 ssl;
server_name www.songreccs.com songreccs.com;
location /static/ {
root /home/user/sonreccs/flaskrec;
}
location / {
include /etc/nginx/proxy_params;
proxy_pass http://localhost:8000;
proxy_redirect off;
}
ssl_certificate /etc/letsencrypt/live/songreccs.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/songreccs.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
listen 80;
server_name www.songreccs.com songreccs.com;
if ($host = www.songreccs.com) {
return 301 https://$host$request_uri;
}
return 404;
}
静态文件的权限:
chmod 755 /home/user && chmod 755 /home/user/sonreccs && chmod 755 /home/user/sonreccs/flaskrec && chmod 755 /home/user/sonreccs/flaskrec/static/