一、 安装nginx

How To Install Nginx on CentOS 7
  • 添加epel扩展仓
    sudo yum install epel-release
  • 安装Nginx
    yum install nginx
  • 开启Nginx
    sudo systemctl start nginx

如果防火墙拦截,可用下面的命令

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
  • 浏览器打开http://your_ip/, 出现Welcome to nginx!说明安装成功

  • 开机启动项

    systemclt enable nginx

服务器默认的根目录/usr/share/nginx/html, 服务器配置目录/etc/nginx/conf.d/,文件要以.conf结尾. 全局配置文件/etc/nginx/nginx.conf

二、安装uwsgi

pip install uwsgi

# 测试uwsgi  如:./Projects/Project/wsgi.py
cd Projects
uwsgi --http :8000 --module Project.wsgi # or
uwsgi --http :8000 --file Project/wsgi.py

uwsgi 常用命令

uwsgi --chdir=/path/to/your/project \
--module=mysite.wsgi:application \
--env DJANGO_SETTINGS_MODULE=mysite.settings \
--master --pidfile=/tmp/project-master.pid \
--socket=127.0.0.1:49152 \ # can also be a file
--processes=5 \ # number of worker processes
--uid=1000 --gid=2000 \ # if root, uwsgi can drop privileges
--harakiri=20 \ # respawn processes taking more than 20 seconds
--max-requests=5000 \ # respawn processes after serving 5000 requests
--vacuum \ # clear environment on exit
--home=/path/to/virtual/env \ # optional path to a virtualenv
--daemonize=/var/log/uwsgi/yourproject.log # background the process 

三、配置nginx

# mysite_nginx.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:8000; # 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 /path/to/your/mysite/uwsgi_params; # the uwsgi_params file you installed
}
}

加入nginx项目配置

sudo ln -s 你的目录/Mxonline/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/

重启nginx

systemctl restart nginx

四、通过配置文件启动uwsgi

新建uwsgi.ini 配置文件, 内容如下:

# mysite_uwsgi.ini file
[uwsgi] # Django-related settings
# the base directory (full path)
chdir = /path/to/Projects
# Django's wsgi file
module = Project.wsgi
# the virtualenv (full path) # process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = 127.0.0.1:8000
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
virtualenv = .virtualenvs_dirs/venv_py logto = /tmp/mylog.log 注:
chdir: 表示需要操作的目录,也就是项目的目录
module: wsgi文件的路径
processes: 进程数
virtualenv:虚拟环境的目录

参考: centos7 下通过nginx+uwsgi部署django应用

参考: Django + Uwsgi + Nginx 的生产环境部署

最新文章

  1. [转载]彻底弄清struct和typedef struct
  2. ssh无密码通信设置
  3. 16083001(古墓丽影GPA)
  4. Windows server 修改mysql端口
  5. [NOIP2013] 提高组 洛谷P1970 花匠
  6. DBA_Oracle Database 11g 面向 DBA 和开发人员的重要特性
  7. saltstack知识点
  8. 该不该将变量设为 null ?
  9. 基于css3的3D立方体旋转特效
  10. 用imagemagick和tesseract-ocr破解简单验证码
  11. OC - 3.OC的三大特性
  12. windows下安装phpcms html/ 文件夹不可写的一种错误以及解决方法
  13. Oracle odi 数据表导出到文件
  14. 剑指架构师系列-spring boot的logback日志记录
  15. vue性能
  16. LOJ #2547 Luogu P4517「JSOI2018」防御网络
  17. 洛谷P2680 运输计划
  18. c# 服务安装后自动启动
  19. 如何一步一步建立CAN通讯
  20. 【转】GDB中应该知道的几个调试方法

热门文章

  1. MySQL Json类型的数据处理
  2. FormData序列化及file文件上传
  3. Docker基础教程(常用命令篇)
  4. RSA实现前端数据加密
  5. PowerBuilder编程新思维1:扩展(Lua)
  6. FFmpeg开发环境构建
  7. SSH无密码登录的原理及配置
  8. 数据结构与算法--最短路径之Dijkstra算法
  9. hadoop的checkpoint检查时间参数设置
  10. openstack-on-centos7之环境准备