【发布时间】:2014-02-16 16:08:16
【问题描述】:
我正在尝试在 OSX (Mavericks) 上设置 django 生产服务器。
这是我的 nginx 服务器配置文件:
server {
listen 80;
server_name localhost;
error_log /pathtoerrorlog;
access_log /pathtoaccesslog;
# serve static files
location ~ ^/static/ {
root /Users/Hello/assets;
expires 30d;
}
# serve media files ~ ^
location ~ ^/media/ {
root /Users/Hello/assets;
expires 30d;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://localhost:8000;
}
}
这是 nginx.conf 配置文件
user www-data;
worker_processes 4;
error_log /var/log/nginx/error.log;
events {
worker_connections 4092;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_bucket_size 64;
gzip on;
gzip_disable "msie6";
include /etc/nginx/sites-enabled/*;
}
我在系统上创建了一个名为 www-data 的用户,并授予了以下访问权限:
sudo chown -R www-data:www-data /usr/local/etc/nginx
sudo chown -R www-data:www-data /etc/nginx
sudo chown -R www-data:www-data /var/log/nginx
我启动 gunicorn 时没有任何错误,nginx 也是如此。
在浏览器中,localhost 将我重定向到 django 应用程序,但不显示静态媒体。正如我在 nginx 错误日志中看到的那样,这是我得到的一个示例错误(在所有静态内容中):
2014/01/25 20:16:23 [error] 35068#0: *68 open() "/Users/Hello/assets/static/css/base.css" failed (13: Permission denied),
client: 127.0.0.1, server: localhost, request: "GET /static/css/base.css HTTP/1.1", host: "localhost", referrer: "http://localhost/"
我尝试使用 sudo chown -R www-data:www-data assets 更改 /Users/Hello/assets 的权限,但没有帮助。 -R 777 也不起作用。
请建议我哪里出错了。谢谢!
【问题讨论】:
标签: django macos nginx gunicorn