应 云友 - “mango爱好 ” 在
帖子 要求,找在 CentOS 7 系统安装 nginx + uWSGI + Diango 的资料。
找到一篇英文的,粗略翻译及实践如下,此例中是假设将相应的文件放在 liujia 用户目录下(/home/liujia),以普通用户 liujia 用户登录到控制台:
1. 添加 EPEL 软件源:
sudo yum install epel-release
[attachment=84774]
2. 安装 pip 工具:
sudo yum install python-pip
3. 安装 python 虚拟环境工具:
sudo pip install virtualenv virtualenvwrapper
[attachment=84775]
4. 更改bash Shell的设置:
echo "export WORKON_HOME=~/Env" >> ~/.bashrc
echo "source /usr/bin/virtualenvwrapper.sh" >> ~/.bashrc
source ~/.bashrc
5. 创建第一个python应用:
mkvirtualenv firstsite
6. 安装 diango
pip install django
7. 生成相应的目录:
cd ~
django-admin.py startproject firstsite
8. 完成基本设置,如设置管理用户名和密码:
cd ~/firstsite
./manage.py migrate
./manage.py createsuperuser
9. 编辑配置文件,在末行添加静态文件目录:
vi firstsite/settings.py
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
./manage.py collectstatic
./manage.py runserver 0.0.0.0:8080
sudo yum install python-devel gcc
sudo pip install uwsgi
uwsgi --http :8080 --home /home/user/Env/firstsite --chdir /home/user/firstsite -w firstsite.wsgi
sudo mkdir -p /etc/uwsgi/sites
cd /etc/uwsgi/sites
sudo vi firstsite.ini
[uwsgi]
project = firstsite
username = liujia
base = /home/%(username)
chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = %(project).wsgi:application
master = true
processes = 5
uid = %(username)
socket = /run/uwsgi/%(project).sock
chown-socket = %(username):nginx
chmod-socket = 660
vacuum = true
sudo vi /etc/systemd/system/uwsgi.service
文件内容如下:
[Unit]
Description=uWSGI Emperor service
[Service]
ExecStartPre=/usr/bin/bash -c 'mkdir -p /run/uwsgi; chown liujia:nginx /run/uwsgi'
ExecStart=/usr/bin/uwsgi --emperor /etc/uwsgi/sites
Restart=always
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
[Install]
WantedBy=multi-user.target
sudo yum install nginx
sudo nano /etc/nginx/nginx.conf
增加的内容如下:
server {
listen 80;
server_name portal.anqun.org;
location = favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/liujia/firstsite;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/run/uwsgi/firstsite.sock;
}
}
sudo nginx -t
sudo usermod -a -G liujia nginx
chmod 710 /home/liujia
sudo systemctl start nginx
sudo systemctl start uwsgi
sudo systemctl enable nginx
sudo systemctl enable uwsgi
-------------------------
Package epel-release.noarch 0:7-5 will be installed
-------------------------
-------------------------
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。