请教下下面是NGINX的配置
子域名的主路径是对应的VUE前端项目端口
子域名下面的分路径 /smtools/ 匹配到了对应后端端口的Django项目
但是后端返回的页面没有式样
如何解决?
# ali.12abc.com HTTPS配置
server {
listen 443 ssl;
server_name ali.12abc.com www.ali.12abc.com;
ssl_certificate /nginx-1.22.0/conf/8612865_ali.12abc.com.pem;
ssl_certificate_key /nginx-1.22.0/conf/8612865_ali.12abc.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root /Users/Administrator/PycharmProjects/VueProjects/smtools/dist/;
proxy_pass http://localhost:5173/;
# wss加上下方3行代码
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /smtools/ {
root /Users/Administrator/PycharmProjects/ali_12abc/templates/;
proxy_pass http://192.168.0.8:8020/;
# wss加上下方3行代码
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
nginx
配置示例
location /static/ {
alias /path/to/static/files/;
}
django
配置示例
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
点击f12查看子域名请求静态文件路径,我怀疑是django 里面,静态资源URL,或静态资源设置有误,估计需要添加子域名前缀
首先,你需要排除你打包的部署文件没有问题,可以通过别的web容器测试一下,比如tomcat
如果打的包没有问题,可以配置一下try_files
try_files $uri $uri/ /index.html;
你看看这篇博文思路是否解决了你的问题:https://blog.csdn.net/BQL_Email/article/details/6129630?locationNum=4&fps=1
解决django配合nginx部署后admin样式丢失
如有帮助,望采纳
1、 在项目的settings.py文件里添加以下内容:
STATIC_URL = ‘/static/’
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
1
]
STATIC_ROOT = os.path.join(BASE_DIR, ‘static’)
2、 执行下面的命令将admin的样式文件拷贝到static文件夹里
python manage.py collectstatic
实际就是往static文件夹里增添了两个文件夹:admin、django_extensions。
3、nginx配置文件中,将新生成的static文件夹替换掉原先的文件夹。