Ubuntu Nginx uwsgi django 初试

/**************************************************************************************
 *                         Ubuntu Nginx uwsgi django 初试
 * 说明:
 *     最近打算通过Python搭建一个数据收集的网站,先做一个搭建测试。
 *
 *                                                  2016-8-5 深圳 南山平山村 曾剑锋
 *************************************************************************************/

一、参考文章:
    1. Ubuntu下搭建Nginx+Uwsgi+Python+Mysql开发环境
        http://blog.csdn.net/hchuchuan/article/details/49718521
    2. 基于nginx和uWSGI在Ubuntu上部署Django
        http://www.jianshu.com/p/e6ff4a28ab5a
    3. Install uwsgi 1.2.5 via pip
        http://askubuntu.com/questions/182313/install-uwsgi-1-2-5-via-pip
    4. How To Install the Django Web Framework on Ubuntu 14.04
        https://www.digitalocean.com/community/tutorials/how-to-install-the-django-web-framework-on-ubuntu-14-04
    5. Nginx+uWSGI 入门
        http://my.oschina.net/u/877567/blog/201577

二、Django目录结构:
    zengjf@zengjf:~/website$ pwd
    /home/zengjf/website
    zengjf@zengjf:~/website$ tree
    .
    └── mysite
        ├── manage.py
        └── mysite
            ├── __init__.py
            ├── __init__.pyc
            ├── settings.py
            ├── settings.pyc
            ├── urls.py
            ├── urls.pyc
            └── wsgi.py

    2 directories, 8 files
    zengjf@zengjf:~/website$

三、nginx配置:
    root@zengjf:/etc/nginx/sites-available# pwd
    /etc/nginx/sites-available
    root@zengjf:/etc/nginx/sites-available# cat default
    # You may add here your
    # server {
    #   ...
    # }
    # statements for each of your virtual hosts to this file

    ##
    # You should look at the following URL's in order to grasp a solid understanding
    # of Nginx configuration files in order to fully unleash the power of Nginx.
    # http://wiki.nginx.org/Pitfalls
    # http://wiki.nginx.org/QuickStart
    # http://wiki.nginx.org/Configuration
    #
    # Generally, you will want to move this file somewhere, and start with a clean
    # file but keep this around for reference. Or just disable in sites-enabled.
    #
    # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
    ##

    server {
        listen 8000 default_server;
        listen [::]:8000 default_server ipv6only=on;

        root /home/zengjf/website/mysite;
        index index.html index.htm;

        # Make site accessible from http://localhost/
        server_name localhost;

        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            # try_files $uri $uri/ =404;
            include  uwsgi_params;
            uwsgi_pass  127.0.0.1:9091;              #必须和uwsgi中的设置一致
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
        }

        # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
        #location /RequestDenied {
        #   proxy_pass http://127.0.0.1:8080;
        #}

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        #error_page 500 502 503 504 /50x.html;
        #location = /50x.html {
        #   root /usr/share/nginx/html;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #   fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #   # With php5-cgi alone:
        #   fastcgi_pass 127.0.0.1:9000;
        #   # With php5-fpm:
        #   fastcgi_pass unix:/var/run/php5-fpm.sock;
        #   fastcgi_index index.php;
        #   include fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #   deny all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #   listen 8000;
    #   listen somename:8080;
    #   server_name somename alias another.alias;
    #   root html;
    #   index index.html index.htm;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
    #   }
    #}

    # HTTPS server
    #
    #server {
    #   listen 443;
    #   server_name localhost;
    #
    #   root html;
    #   index index.html index.htm;
    #
    #   ssl on;
    #   ssl_certificate cert.pem;
    #   ssl_certificate_key cert.key;
    #
    #   ssl_session_timeout 5m;
    #
    #   ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    #   ssl_ciphers "HIGH:!aNULL:!MD5 or HIGH:!aNULL:!MD5:!3DES";
    #   ssl_prefer_server_ciphers on;
    #
    #   location / {
    #       try_files $uri $uri/ =404;
    #   }
    #}
    root@zengjf:/etc/nginx/sites-available# 

四、运行uwsgi命令:
    root@zengjf:/home/zengjf/website# uwsgi --socket 127.0.0.1:9091 --chdir /home/zengjf/website/mysite --wsgi-file mysite/wsgi.py --master --processes 2 --threads 2
    *** Starting uWSGI 2.0.13.1 (64bit) on [Fri Aug  5 21:47:55 2016] ***
    compiled with version: 4.8.4 on 04 August 2016 21:12:52
    os: Linux-3.16.0-30-generic #40~14.04.1-Ubuntu SMP Thu Jan 15 17:43:14 UTC 2015
    nodename: zengjf
    machine: x86_64
    clock source: unix
    pcre jit disabled
    detected number of CPU cores: 2
    current working directory: /home/zengjf/website
    detected binary path: /usr/local/bin/uwsgi
    uWSGI running as root, you can use --uid/--gid/--chroot options
    *** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
    chdir() to /home/zengjf/website/mysite
    your processes number limit is 15313
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    thunder lock: disabled (you can enable it with --thunder-lock)
    uwsgi socket 0 bound to TCP address 127.0.0.1:9091 fd 3
    Python version: 2.7.6 (default, Jun 22 2015, 18:01:27)  [GCC 4.8.2]
    Python main interpreter initialized at 0x24ae640
    python threads support enabled
    your server socket listen backlog is limited to 100 connections
    your mercy for graceful operations on workers is 60 seconds
    mapped 249168 bytes (243 KB) for 4 cores
    *** Operational MODE: preforking+threaded ***
    WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x24ae640 pid: 4120 (default app)
    *** uWSGI is running in multiple interpreter mode ***
    spawned uWSGI master process (pid: 4120)
    spawned uWSGI worker 1 (pid: 4121, cores: 2)
    spawned uWSGI worker 2 (pid: 4122, cores: 2)
    

 

时间: 2024-09-17 02:57:28

Ubuntu Nginx uwsgi django 初试的相关文章

nginx+uwsgi+django中的uwsgi.ini配置问题

问题描述 nginx+uwsgi+django中的uwsgi.ini配置问题 最近配置了nginx+uwsgi+django,其中项目目录下我新建了uwsgi.ini配置文件 [uwsgi] socket = 127.0.0.1:8088 master = true pidfile = /tmp/uwsgi.pid processes = 8 chdir = /home/test daemonize=/home/log/uwsgi.log module = test.wsgi:applicati

如何将django部署从顶级目录迁移到子目录下(NGINX UWSGI DJANGO)

因为公司网站合并,要将我们的DJANGO项目从IP的顶级目录迁移到域名的二级目录. 以前硬编码的URL可惨了. 还涉及到upload目录,静态目录,websocket目录. 全用{% url %}问题不太大. nginx分前后两级,uwsgi配置要作相应更改,django的setting需要变量登陆网址. 这样,在正式网站访问二级目录,测试环境仍然可以根目录访问. nginx_front: server { listen 80; server_name localhost; location /

Nginx+uWSGI+Django+Python环境安装配置详解

一.安装PYTHON2.7.7: [root@hz tools]# pwd /byrd/tools [root@hz tools]# wget https://www.python.org/ftp/python/2.7.7/Python-2.7.7.tgz [root@hz tools]# tar zxf Python-2.7.7.tgz [root@hz tools]# cd Python-2.7.7 [root@hz Python-2.7.7]# ./configure --prefix=/

通过Nginx部署Django(基于ubuntu)

Django的部署可以有很多方式,采用nginx+uwsgi的方式是其中比较常见的一种方式. 在这种方式中,我们的通常做法是,将nginx作为服务器最前端,它将接收WEB的所有请求,统一管理请求.nginx把所有静态请求自己来处理(这是NGINX的强项).然后,NGINX将所有非静态请求通过uwsgi传递给Django,由Django来进行处理,从而完成一次WEB请求. 可见,uwsgi的作用就类似一个桥接器.起到桥梁的作用. Linux的强项是用来做服务器,所以,下面的整个部署过程我们选择在U

Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程_python

具体环境: Ubuntu 14.04 Python 2.7.6 Django 1.7.1 Virtualenv name:test Nginx uwsgi 假设 项目文件夹位于 /data/www/ts 设置保存在 ./conf 复制代码 代码如下: virtualenv name = test domain name = example.com django+uwsgi的部署实在是太蛋疼了..网上已有的教程似乎有新版本的兼容问题.最后跑到uwsgi官网上找的教程终于跑通了.. 不过官网的教程似

Django+Nginx+uwsgi的部署

先决条件: nginx(>0.8):uwsgi:django: flup 下载地址: wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz 安装: sudo apt-get libxml2-dev python-dev flup和django   都是用 python setup.py install tar zxvf uwsgi-0.9.9.2.tar.gz cd uwsgi-0.9.9.2 make -f Makefil

CentOS6.5_64下 nginx+uwsgi+Python +多站点环境搭建 python web django 框架

nginx+uwsgi+Python环境介绍: 系统:CentOS6.5_64_mini nginx版本:nginx-1.6.0 python版本:Python2.7.8   第一部分系统设置 1:查看系统内核 #  uname -r 2.6.32-431.el6.x86_64 2:更新内核 #  yum -y install kernel 3:重启系统 #  reboot 4:重启后查看是否启用新内核 #  uname -r 2.6.32-431.20.5.el6.x86_64 5:可以删除老

在Debian下配置Python+Django+Nginx+uWSGI+MySQL的教程_python

最近尝试把项目迁移到Python环境下,特别新装了一台干净的Debian系统,准备重新配置环境,上网找了一些运行Python Web的环境方案,最后敲定Nginx+uWSGI组合,Nginx用得比较多,熟练些:uWSGI据说性能不错,想尝试一下. 网上大部分教程都是要求到uWSGI官方网站下载源码包,然后通过编译的方式安装,比如对于一台新Debian系统,可以通过下面的命令安装: apt-get update apt-get upgrade apt-get install build-essen

uwsgi 配置 初试

/************************************************************************************** * uwsgi 配置 初试 * 说明: * 将uwsgi命令行参数改成配置文件中的参数. * * 2016-8-6 深圳 南山平山村 曾剑锋 *************************************************************************************/ 一.sh