django+;nginx+;静态文件上的uwsgi 404
我有一个django应用程序,使用nginx和uwsgi提供服务。我的静态文件返回404。我已将文件的所有权设置为与nginx用户名相对应。静态文件夹的路径是直接从终端复制的,我运行了collectstatic(通过django开发服务器成功地提供了静态文件)。我也跑了django+;nginx+;静态文件上的uwsgi 404,django,nginx,uwsgi,Django,Nginx,Uwsgi,我有一个django应用程序,使用nginx和uwsgi提供服务。我的静态文件返回404。我已将文件的所有权设置为与nginx用户名相对应。静态文件夹的路径是直接从终端复制的,我运行了collectstatic(通过django开发服务器成功地提供了静态文件)。我也跑了 chown -R username:username /home 及 我尝试了alias和root 静态根目录在my settings.py中 STATIC_ROOT = os.path.join(BASE_DIR, "st
chown -R username:username /home
及
我尝试了alias和root
静态根目录在my settings.py中
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
这是我的nginx.conf:
user username;
worker_processes 1;
events {
worker_connections 1024;
}
http {
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
application/x-javascript
application/atom+xml;
# Configuration containing list of application servers
upstream app_servers {
server 127.0.0.1:8080;
# server 127.0.0.1:8081;
# ..
# .
}
# Configuration for Nginx
server {
# Running port
listen 80;
# Settings to serve static files
location /static/ {
# Example:
# root /full/path/to/application/static/file/dir;
alias /home/myapp/myapp/static/;
}
# Serve a static file (ex. favico)
# outside /static directory
location = /favico.ico {
root /app/favico.ico;
}
# Proxy connections to the application servers
# app_servers
location / {
proxy_pass http://app_servers;
proxy_redirect off;
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;
}
}
}
将
/home
目录发送给某些用户是个坏主意。该目录应属于root目录。将其更改回原来的状态:
chown root:root /home
chmod u=rwx,g=rx,o=rx /home
(您运行的chmod可能没有更改其权限,但最好确定一下,因此上面的第二个命令会将其恢复为原来的状态。)
您说您的项目在/home/username
下,但nginx配置显示/home/myapp
。解决这个问题。我假设它是/home/username
。/home/username
需要一些权限才能修复:
chmod o+rx /home/username
另请参见(我的文章)项目的完整路径是什么?/home/username/uswgi tutorial/mysite
chmod o+rx /home/username