server { listen 443 ssl;#在端口443上监听HTTPS流量server_name 54.198.4.208; #替换为您的实际域名或IP地址
# SSL/TLS Certificate Configuration
ssl_certificate /etc/nginx/selfsigned.crt; # Path to self-signed SSL certificate
ssl_certificate_key /etc/nginx/selfsigned.key; # Path to self-signed SSL certificate key
# Location Blocks for Handling Requests
location = /favicon.ico {
access_log off;
log_not_found off;
}
location /static/ {
alias /home/ubuntu/logins/staticfiles/; # Path to the root directory of your Django project
}
location / {
proxy_pass https://54.198.4.208:8000; # Replace with your Django app's IP and port
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-Proto $scheme;
}
}这是我的nginix配置,当我尝试http://54.198.4.208:8000/static/style.css这个网址我得到了文件找不到404错误所有我的静态文件都存在于正确的目录,即使我试图打开一个静态文件手动通过这个路径,我得到了staitc文件在正确的路径也我检查了权限也一切都很好,但仍然无法工作
我试图手动查看路径是否有静态文件或但它在正确的位置有所有静态文件
1条答案
按热度按时间z31licg01#
我使用下面的nginx配置,一切都是正确的。试试这个代码。