簡體   English   中英

nginx禁止提供Django靜態和媒體文件403

[英]nginx serving django static and media files 403 forbidden

首先,我嘗試從其他問題中找到一種解決方案,但是它們對我來說不起作用,因此我創建了一個新問題。

詳細信息如下:

1我嘗試在nginx.conf中更改用戶

#user www-data;
user me;
worker_processes 4;
pid /run/nginx.pid;
....

2在可用的站點和啟用的站點上添加並鏈接conf

server {
    add_header Access-Control-Allow-Origin *.mysite.com;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
    listen  80;
    server_name mysite.com;
    access_log /var/log/nginx/hitek.access.log;
    error_log /var/log/nginx/hitek.error.log;

    location / {
        proxy_pass http://127.0.0.1:8010;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location ~ ^/media/  {
        #alias /var/www/html/mysite/media;
        alias /home/me/website/mysite/media;
        #alias /home/www-data/website/website/mysite/media;
        expires 1h;
        access_log off;
    }

    location ~ ^/static/ {
        #alias /var/www/html/mysite/collected_static;
        alias /home/me/website/mysite/collected_static;
        #alias /home/www-data/website/website/mysite/collected_static;
        expires 1h;
        access_log off;
        include /etc/nginx/mime.types;
    }
}

您會看到4行注釋,我嘗試在此位置復制collectd_static和media文件夾,但失敗。 當然,我更改了對此文件夾的權限。

~/website$ ls -alt
drwxrwxrwx 8 me me 4096 Sep 11 14:43 mysite
drwxr-xr-x 6 me me 4096 Sep  8 14:30 ..
drwxrwxrwx 4 me me 4096 Sep  7 11:41 .

誰可以回答? 謝謝。

在路徑的末尾添加斜杠。 否則,Nginx無法找到文件。

alias /home/me/website/mysite/media/;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM