centos6.7+nginx+uwsgi+django
来源:互联网 发布:万龙滑雪场 知乎 编辑:程序博客网 时间:2024/05/21 01:53
参考:http://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/tutorials/Django_and_nginx.html
1. 基本依赖包安装:
yum groupinstall "Development tools" -yyum install zlib-devel bzip2-devel pcre-devel openssl-devel python-devel ncurses-devel mysql-devel sqlite-devel readline-devel tk-devel -y
2. 安装python2.7.11
tar -zxvf Python-2.7.tgz
cd Python-2.7.11
./configure --enable-shared --prefix=/usr
make
make install
## delete original link
rm /usr/bin/python
##create new link
ln -s /usr/bin/python2.7 /usr/bin/python
##create the file
vim /etc/ld.so.conf.d/python2.7.conf
##add the content
/usr/lib
##run the command
ldconfig
3. 下载并安装setuptools
python setup.py install
4. 安装pip
python setup.py install
5. 安装django1.8.17
pip install django==1.8.17
6. 安装uwsgi
pip install uwsgi
7. 安装nginx
./configure --with-http_stub_status_module --with-http_gzip_static_module
make
make install
8. 测试uwsgi是否正常工作
创建测试文件test.py
# test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"] # python3
#return ["Hello World"] # python2
运行以下命令,并访问http://127.0.0.1:8000
uwsgiuwsgi --http :8000 --wsgi-file test.py
9. 配置uwsgi+django
用django-admin命令创建mysite站点
django startproject mysite
测试django工作是否正常,运行djago,访问http://127.0.0.1:8000
python manage.py runserver 0.0.0.0:8000
测试django+uwsgi工作是否正常,运行以下命令并访问http://127.0.0.1:8000
uwsgi --http :8000 --module mysite.wsgi
10. 配置uwsgi+django+nginx
配置ningx.conf文件
# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name .example.com; # substitute your machine's IP address or FQDN
charset utf-8;
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /usr/local/nginx/conf/uwsgi_params; # the uwsgi_params file you installed
}
}
**********以端口8001启动uwsgi加载测试文件test.py文件,访问http://127.0.0.1
uwsgi --socket :8001 --wsgi-file test.py --chmod-socket=666
启动nginx
/usr/local/nginx/sbin/nginx
**************以sock方式启动uwsgi加载测试文件test.py文件,访问http://127.0.0.1
在/home创建mysite.sock空文件,并更改nginx.conf文件
upstream django {
server unix:///home/mysite.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
重新启动nginx
uwsgi --socket mysite.sock --wsgi-file test.py --chmod-socket=666
在/home/mysite目录下运行以下命令,并访问http://127.0.0.1
uwsgi --socket /home/mysite.sock --module mysite.wsgi --chmod-socket=666
****配置mysite_ningx.conf和mysite_uwsgi_ini文件
step1:nginx.conf的http配置中添加
include /usr/local/nginx/conf/mysite_nginx.conf;
step2:并创建mysite_nginx.conf
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///home/mysite.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
# configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name .example.com; # substitute your machine's IP address or FQDN
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /path/to/your/mysite/media; # your Django project's media files - amend as required
}
location /static {
alias /path/to/your/mysite/static; # your Django project's static files - amend as required
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /usr/local/nginx/conf/uwsgi_params; # the uwsgi_params file you installed
}
}
step3:更改nginx.conf文件的listen的默认80端口改为8000,避免和mysite_nginx.conf监听端口重复
step4:创建/etc/uwsgi/mysite_uwsgi_ini
# mysite_uwsgi.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /home/mysite
# Django's wsgi file
module = mysite.wsgi
# the virtualenv (full path)
#home = /path/to/virtualenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /home/mysite.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = true
step5: 在django 的setting.py文件配置allowhost,如
ALLOWED_HOSTS = ['172.17.*.*']
uwsgi -i mysite_uwsgi.ini
/usr/local/nginx/sbin/nginx
#杀掉当前端口的进程
fuser -k 80/tcp
#杀掉当前占用的yum进程
rm -rf /var/run/yum.pid
0 0
- centos6.7+nginx+uwsgi+django
- CentOS6.4+uwsgi+nginx+django
- CentOS6.4 搭建Django+Nginx+uWSGI
- centos6.5+Django+mysql+nginx+uwsgi
- centos6.6+django+nginx+uwsgi环境配置
- centos6.5下配置django+uwsgi+nginx
- centos6.5安装nginx+python+uwsgi+django
- CentOS6.下Nginx+django+uwsgi配置多个虚拟机
- CentOS6.5+Django+Nginx+MySQL+uwsgi 阿里云环境部署
- 阿里云上CentOS6.5部署Django+nginx+uwsgi
- django + nginx + uwsgi
- Nginx + uwsgi + django 配置
- Django+Nginx+uwsgi部署
- nginx+uwsgi+django
- nginx uwsgi django部署
- nginx uwsgi 部署django
- nginx+uwsgi+django
- django nginx+uwsgi部署
- Java 线程面试题 Top 50
- eclipse中使用Maven新建Servlet2.5的Web项目
- Eclipse快捷键
- linux下安装使用apache tomcat
- Maven中使用Jetty容器
- centos6.7+nginx+uwsgi+django
- Maven入门-3.pom文件和settings文件
- 数据库功能函数
- 汇编语言笔记二
- 笔记111-120
- java中线程总结
- Maven入门-4.Maven的依赖
- Maven入门-5.Maven的聚合和继承
- 笔记121-133