在云服务器上从零搭建nginx+uwsgi+django服务器
来源:互联网 发布:自学网站美工 编辑:程序博客网 时间:2024/05/21 09:30
笔者使用腾讯云服务器,centos7 64位镜像,自带 python 2.7.5 无需安装
现在安装 pip
wget --no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz tar zvxf 1.5.5.tar.gz cd pip-1.5.5/ python setup.py install
可能出现错误:
ImportError: No module named setuptools
需要安装setuptools
wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gztar zxvf setuptools-0.6c11.tar.gzcd setuptools-0.6c11python setup.py install
安装mysql:(参考http://www.centoscn.com/mysql/2016/0315/6844.html )
yum install libaio # 安装依赖包,这里已经安装 yum install mysql-community-server
配置mysql:
whereis mysql # 可以查看安装目录 systemctl start mysqld # 启动服务 systemctl status mysqld # 查看状态 mysql_secure_installation # 安全设置
字符集设置:
修改 /etc/my.cnf 文件,添加字符集的设置
[mysqld] character_set_server = utf8[mysql]default-character-set = utf8
重启 MySQLsystemctl restart mysqld
安装git:
yum install git
安装nginx:
yum install nginx
pip安装uwsgi:
pip install uwsgi
出现错误:you need a C compiler to build uWSGIyum install -y gcc gcc-c++
错误:fatal error: Python.h
yum install python-devel
安装django依赖库:
sudo yum install python-develsudo yum install zlib-develsudo yum install libjpeg-turbo-develpip install pillow
使用uwsgi运行测试文件:
uwsgi –http :8001 –wsgi-file test.py
test.py
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"]
使用git导入项目:
git initgit config -global user.email "..."git config --global user.name "..."git remote add origin https://github.com/...git fetch origin linuxgit commit –m “init” # 先commit一次创建本地分支git merge origin/linux
配置nginx:
whereis nginx # 查看nginx安装目录
编辑配置文件nginx.conf:
server { listen 8080; server_name www.yours.cn; root /root/SHBproject; index root.template.login.html # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; access_log /var/log/nginx/mindg.access.log; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9001; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
启动uwsgi:
uwsgi --socket 127.0.0.1:9001 --chdir /root/SHBproject/ --wsgi-file /root/SHBproject/SecondHandsBook/wsgi.py -d uwsgi.log # 运行uwsgi
问题: Internal Server Error
修改wsgi.py:
import osimport sys from django.core.wsgi import get_wsgi_application os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' application = get_wsgi_application()
测试 uwsgi –http :8001 –wsgi-file SecondHandsBook/wsgi.py
发现是django数据库配置问题,不加赘述。
注意:
yum install -y mysql-devel python-devel python-setuptools pip install MySQL-python
错误:
probably another instance of uWSGI is running on the same address
查看端口调用:
lsof -i :9001 kill -9 5632
重启:
uwsgi --socket 127.0.0.1:9001 --chdir /root/SHBproject/ --wsgi-file /root/SHBproject/SecondHandsBook/wsgi.py
使用ini启动uwsgi:
uwsig.ini
[uwsgi] vhost = false socket = 127.0.0.1:9001 master = true enable-threads = true daemonize = /var/log/uwsgi.log #后台启动,并把日志记录到指定文件 workers = 1 wsgi-file = /root/SHBproject/SecondHandsBook/wsgi.pychdir = /root/SHBproject
启动命令:uwsgi –ini /root/SHBproject/uwsgi.ini&
部署就到此为止了,未来的优化会持续更新。。。
更新git仓库:
git branch qqcloud git checkout qqcloud git commit -m "server management" –a git push -u origin qqcloud git add uwsgi.ini git commit -m "add uwsgi.ini"
还有一些问题:
1. The _imagingft C module is not installed
这个是由于PIL没有编译freetype导致的,
https://my.oschina.net/u/993130/blog/214454
2. 权限问题导致Nginx 403 Forbidden错误的解决方法
在nginx.conf头部加入一行:user root;
3. 配置location的时候一定要注意绝对路径和相对路径的使用
location /static/ { alias /root/SHBproject/static/; } location /media/ { alias /root/SHBproject/media/; } location / { include uwsgi_params; uwsgi_pass 127.0.0.1:9001; }
- 在云服务器上从零搭建nginx+uwsgi+django服务器
- Django + Nginx + Uwsgi 配置服务器
- Nginx+uwsgi+Django 搭建一个简单的web服务器
- Ubuntu+Django+Nginx+uWSGI+Mysql搭建Python Web服务器
- 在树莓派上搭建 Nginx + uWSGI + Django 架构服务器的过程中所学到的
- 从零开始在 Ubuntu 下部署 Nginx uWSGI Django 服务器
- 基于ubuntu(阿里云)的nginx+uwsgi+django的服务器搭建(到处是坑)
- nginx uwsgi django supervisor 服务器配置
- nginx+uwsgi+django(restframework)服务器部署
- 配置搭建阿里云服务器nginx+uwsgi (python)
- 从零搭建阿里云Web服务器
- 从零搭建 repo 服务器
- 实现简单的"nginx+uwsgi+django"的服务器架构
- 实现简单的"nginx+uwsgi+django"的服务器架构
- 基于Ubuntu16.04服务器的Nginx+Django+Uwsgi配置
- 在阿里云ECS上从零开始搭建nginx服务器
- nginx+uwsgi+django+linux搭建
- nginx django uwsgi搭建网站
- oracle 非分区表转分区表
- USB鼠标设备驱动程序简单实现(二)
- 【javaScript】报getElementId()为Null的错误
- Oracle trunc()函数的用法
- 计算机书籍汇总
- 在云服务器上从零搭建nginx+uwsgi+django服务器
- spring mvc 返回json乱码
- C语言中#define使用方法
- api文档工具-将json对象转行表
- 归并排序之数组和链表
- 微信小程序开发常见问题FAQ之七
- calcHist的使用中严重的错误和误区!!!!!!!为什么所有的文章都没有指出??
- 秒杀系统架构分析与实战
- input 输入法禁用