【发布时间】:2017-08-03 01:42:06
【问题描述】:
我正在尝试将 django 应用程序与 wordpress 一起部署在同一个域下。 Django 应用程序应该在一个子 URL 下:“domain.com/djangoapp”。我尝试在 nginx conf 文件以及 django settings.py 中将 SCRIPT_NAME 变量设置为该前缀。它工作并且可以在 /djangoapp url 下访问 django 应用程序,但不会加载静态文件。
我有以下 nginx 配置:
server {
server_name domain.com www.domain.com;
root /var/www/domain.com/htdocs;
index index.php index.html index.htm;
include common/redis.conf;
include common/wpcommon.conf;
location /static {
root /home/user/project;
}
location /djangoapp/ {
include proxy_params;
proxy_pass http://unix:/home/user/project/project.sock
proxy_set_header SCRIPT_NAME /djangoapp;
}
}
和 settings.py:
FORCE_SCRIPT_NAME = '/djangoapp'
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
我还尝试将 django 应用程序部署在单独的域上,并且静态文件确实会加载。除了 SCRIPT_NAME 部分之外,配置是相同的。 有人可以帮忙吗?
【问题讨论】:
-
你运行
manage.py collectstatic了吗?见docs.djangoproject.com/en/1.10/ref/contrib/staticfiles/… -
当然。 Nginx设置指向
collectstatic创建的目录
标签: python django wordpress nginx gunicorn