昨天是利用Django自带的runserver部署的服务器,但是由于runserver比较不稳定,因此决定采用uWSGI+nginx进行部署。

昨天已经安装好了uwsgi和nginx,使用该指令打开8000访问端口:

uwsgi --http :8000 --chdir /home/icourse/iCourse --module iCourse.wsgi

然后利用笔记本和平板电脑分别访问,发现页面一片空白。

服务器后台的错误信息,:

[pid: 31549|app: 0|req: 1/1] 10.137.174.21 () {70 vars in 1019 bytes} [Sat Oct 28 11:25:09 2017] GET / => generated 442 bytes in 41 msecs (HTTP/1.1 200) 3 headers in 109 bytes (1 switches on core 0)
Not Found: /static/css/app.da991ce51b08fcdf1dfde7fb00a9d017.css
[pid: 31549|app: 0|req: 2/2] 10.137.174.21 () {70 vars in 1161 bytes} [Sat Oct 28 11:25:09 2017] GET /static/css/app.da991ce51b08fcdf1dfde7fb00a9d017.css => generated 2200 bytes in 12 msecs (HTTP/1.1 404) 3 headers in 102 bytes (1 switches on core 0)
Not Found: /static/js/vendor.77bc9ca30309ef3aa829.js
[pid: 31550|app: 0|req: 1/3] 10.137.174.21 () {70 vars in 1102 bytes} [Sat Oct 28 11:25:09 2017] GET /static/js/vendor.77bc9ca30309ef3aa829.js => generated 2167 bytes in 28 msecs (HTTP/1.1 404) 3 headers in 102 bytes (1 switches on core 0)
Not Found: /static/js/app.d206dc1dbbd970ddb09c.js
Not Found: /static/js/manifest.34417dabbe075f84e501.js
[pid: 31547|app: 0|req: 1/4] 10.137.174.21 () {70 vars in 1090 bytes} [Sat Oct 28 11:25:09 2017] GET /static/js/app.d206dc1dbbd970ddb09c.js => generated 2158 bytes in 49 msecs (HTTP/1.1 404) 3 headers in 102 bytes (1 switches on core 0)
[pid: 31548|app: 0|req: 1/5] 10.137.174.21 () {70 vars in 1110 bytes} [Sat Oct 28 11:25:09 2017] GET /static/js/manifest.34417dabbe075f84e501.js => generated 2173 bytes in 44 msecs (HTTP/1.1 404) 3 headers in 102 bytes (1 switches on core 0)
Not Found: /static/js/vendor.77bc9ca30309ef3aa829.js
[pid: 31550|app: 0|req: 2/6] 10.137.174.21 () {70 vars in 1102 bytes} [Sat Oct 28 11:25:09 2017] GET /static/js/vendor.77bc9ca30309ef3aa829.js => generated 2167 bytes in 8 msecs (HTTP/1.1 404) 3 headers in 102 bytes (1 switches on core 0)
Not Found: /static/js/app.d206dc1dbbd970ddb09c.js
[pid: 31550|app: 0|req: 3/7] 10.137.174.21 () {70 vars in 1090 bytes} [Sat Oct 28 11:25:09 2017] GET /static/js/app.d206dc1dbbd970ddb09c.js => generated 2158 bytes in 8 msecs (HTTP/1.1 404) 3 headers in 102 bytes (1 switches on core 0)

之前使用runserver的时候一切正常,换成nginx就出了问题。而且更奇怪的是凡是在runserver时访问过网站的设备,都能在运行uwsgi时访问网页,而其它设备就不行(这个很玄,原因暂时还不清楚)。

经过了一下午的查阅资料,最终解决问题。

首先我在/home/icourse/下建了两个文件,一个是uwsgi8000.ini,一个是nginx.conf,按照网上的代码照猫画虎进行了配置,并将nginx.conf软连接到/etc/nginx/sites-enabled/下:

sudo ln -s ~/home/icourse/nginx.conf /etc/nginx/sites-enabled/

然后运行如下指令:

uwsgi --ini ./uwsgi8000.ini

这就是使用ini的好处,比第一条指令简单多了。

然后发现浏览器提示没有发送信息,后台也没有一点提示。

后来又查找了很多资料,搞清楚了socket和http的概念,个人理解是http(设置为:8000)是提供用户访问的,socket(设置为127.0.0.1:8001)是nginx和uwsgi进行信息交流用的,之前一直用的是socket,没有定义用户访问的接口,所以导致无法连接。

经过了一番修改,nginx.conf内容如下(项目名为iCourse):

upstream django {
server 127.0.0.1:8001; # 和ini文件中的socket保持一致
} server {
listen 8000; # 访问接口
server_name origin_icourse; location / {
include uwsgi_params;
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
uwsgi_param UWSGI_SCRIPT iCourse.wsgi;
uwsgi_param UWSGI_CHDIR /iCourse;
index index.html index.htm;
client_max_body_size 35m;
}
}

uwsgi8000.ini内容如下:

[uwsgi]
socket = 127.0.0.1:8001 # 和conf文件中的server保持一致
chdir = /home/icourse/iCourse # 项目位置
wsgi-file = iCourse/wsgi.py # wsgi.py位置(相对chdir)
master = true
processes = 4
#threads = 2
#module = iCourse.wsgi
vacuum = true # 清除文件
buffer-size = 30000

在此运行uwsgi,发现又回到了一开始的状态,即404错误。折腾了一下午仿佛又回到了原点。

然后又经过一番搜索,发现conf文件中缺少了对static路径的定义,于是在server语句块下又添加了如下代码:

location /static {
alias /home/icourse/iCourse/frontend/dist/static;
}

运行uwsgi,笔记本和移动设备都能加载网页。

最新文章

  1. 深入理解JavaScript中 fn() 和 return fn() 的区别
  2. 构建兼容浏览器的Angularjs web应用
  3. SQL Server 2012实施与管理实战指南(笔记)——Ch6连接的建立和问题排查
  4. [转]Mybatis极其(最)简(好)单(用)的一个分页插件
  5. Java String字符串补0或空格
  6. GL_GL系列 - 会计期间管理分析(案例)
  7. NGUI学习笔记(三):屏幕自适应
  8. jx3dps开发日记
  9. js实现相册翻页,滚动,切换,轮播功能
  10. MySQL 登陆
  11. RocketMQ源码 — 四、 Consumer 接收消息过程
  12. FOR XML PATH 简单介绍
  13. 黄金连分数|2013年蓝桥杯B组题解析第四题-fishers
  14. TCP和UDP协议的比较
  15. UI设计教程学习分享:APP布局
  16. C语言编程流程
  17. 【Android】 导入项目报错的解决方案
  18. 小程序视图层(xx.xml)和逻辑层(xx.js)
  19. Flume定时启动任务 防止挂掉
  20. mybatis三剑客之mybatis-pagehelper分页插件

热门文章

  1. bootStrap中Tab页签切换
  2. CSS过渡动画之transition
  3. curl命令实现上网认证登录
  4. Win10家庭版无法打开策略组问题
  5. 我所理解的selenium之PO设计模式
  6. Android Studio —— java.lang.VerifyError: Verifier rejected class 问题解决
  7. unittest—selenium自动化登录百度绕过校验
  8. while循环计算规则:内循环—外循环!
  9. python 基础篇01
  10. SICP读书笔记 3.4