centos 7 + uwsgi +django+Nginx 安装方法
1、安装wget,gcc-c++ gcc*
yum install -y wget gcc-c++ epel-release
2、安装pip
yum install python-pip
3、升级pip
pip install --upgrade pip
4、安装django1.10.6
pip install django
5、安装MysqL-python
a、下载MysqL-python1.2.5包,地下:https://pypi.Python.org/pypi/MySQL-python/1.2.5
b、unzip MysqL-python-1.2.5
c、yum install MysqL-deve; 不安装这个包,会报EnvironmentError: MysqL_config not found
d、python setup.py install
如果出现:Python.h:没有那个文件或目录
安装 python-devel
sudo yum install python-devel
1、修改settings.py
STATIC_ROOT = os.path.join(BASE_DIR,'static')
2、生成static目录
./manage.py collectstatic
7、安装image组件否则会报PIL错误(需要才安装)
ImportError: No module named PIL
pip install image
8、测试应用是否能正常运行,如果在浏览器里能访问8080端口的内容,即成功
./manage.py runserver 0.0.0.0:8080
9、安装Python开发包和uWSGI
sudo pip install uwsgi
10、测试uWSGI是否能正常运行:
uwsgi —http:8080 —chdir /opt/project -w mysite.wsgi
11、创建 uWSGI运行的配置文件 uwsgi.conf
mkdir -p /etc/uwsgi
vi /et c/uwsgi/uwsgi.conf
[uwsgi]
chdir = /opt/hn_dataweb
socket = /opt/hn_dataweb/hn_dataweb.sock
wsgi-file = /opt/hn_dataweb/hn_dataweb/wsgi.py
master = true
uid = root
processes = 2
threads = 4
chmod-socket = 666
chown-socket = root:Nginx
vacuum = true
12、安装supervisor
sudo pip install supervisor
echo_supervisord_conf>/etc/supervisord.conf
[program:hn_dataweb]
command=/usr/bin/uwsgi --ini /etc/uwsgi/uwsgi.conf --chdir /opt/hn_dataweb
directory=//opt/hn_dataweb
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true
注意:--ini /etc/uwsgi/uwsgi.conf此文件要和前面建立的uwsgi文件地址一致。
15、安装Nginx
sudo yum install Nginx
加入以下内容:
server {
listen 80;
server_name 127.0.0.1;
charset utf-8;
access_log /var/log/Nginx/access.log;
client_max_body_size 75M;
location /media {
alias /opt/hn_dataweb/media;
}
location /static {
alias /opt/hn_dataweb/static;
}
location / {
root /opt/hn_dataweb;
uwsgi_pass unix:///opt/hn_dataweb/hn_dataweb.sock;
# 此文件一定要和uwsgi.conf 中配置的sock文件一致,否则会有问题
include /etc/Nginx/uwsgi_params;
}
}
原文链接:https://www.f2er.com/centos/378153.html