nginx+django+fastcgi配置

安裝環境介紹:
   python2.7.10
   django1.7.9
   linux CentOS release 6.5 (Final) 64


1、fastcgi插件的安裝安裝與配置
    https://www.saddi.com/software/flup/dist/  下載 flup-1.0.2.tar.gz
    tar flup-1.0.2.tar.gz
    cd flup-1.0.2
    python setup.py install
    
    通過supervisor啓動fastcgi進程
        [program:myweb_fcgi]
        command=python /var/www/myweb/manage.py runfcgi protocol=fcgi  host=0.0.0.0  port=8000 daemonize=false method=threaded umask=007 maxspare=6
        autostart = true
        startsecs = 5
        user=myuser
        redirect_stderr = true
        stdout_logfile_maxbytes = 20MB
        stdout_logfile_backups = 20
        stdout_logfile =/var/log/fsgi/myweb_fsgi.log
        
    /usr/local/python/bin/supervisorctl reload myweb_fcgi
    /usr/local/python/bin/supervisorctl restart myweb_fcgi
        


2、nginx的安裝與配置
    安裝:
      ./configure
       make
       make install
    
    配置:
        server {
              listen       6666;
              location / {
                 proxy_connect_timeout 600;
                 proxy_send_timeout 600;
                 proxy_read_timeout 600;
                 server_name_in_redirect off;
                 proxy_set_header Host $host:$server_port;
                 proxy_set_header X-Real-IP $remote_addr;
                 proxy_set_header REMOTE-HOST $remote_addr;
                 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                 client_max_body_size    300m;
                 fastcgi_pass  127.0.0.1:8000;
                 include fastcgi.conf;
             }
        
             location /media/ {
                  alias /var/www/myweb/static/;
             }
             location /static/ {
                  alias /var/www/myweb/static/;
             }
         }
        
    特別注意:
        nginx默認的fastcgi.conf.default 中的配置一定要刪除 fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        否則運行有問題
        
    
    附帶一份fastcgi.conf
    fastcgi_pass_header Authorization;
    fastcgi_intercept_errors off;
    fastcgi_param PATH_INFO         $fastcgi_script_name;
    fastcgi_param REQUEST_METHOD      $request_method;
    fastcgi_param QUERY_STRING        $query_string;
    fastcgi_param CONTENT_TYPE        $content_type;
    fastcgi_param CONTENT_LENGTH      $content_length;
    fastcgi_param SERVER_PORT         $server_port;
    fastcgi_param SERVER_PROTOCOL     $server_protocol;
    fastcgi_param SERVER_NAME         $server_name;
    fastcgi_param REQUEST_URI         $request_uri;
    fastcgi_param DOCUMENT_URI      $document_uri;
    fastcgi_param DOCUMENT_ROOT          $document_root;
    fastcgi_param SERVER_ADDR            $server_addr;
    fastcgi_param REMOTE_USER         $remote_user;
    fastcgi_param REMOTE_ADDR         $remote_addr;
    fastcgi_param REMOTE_PORT         $remote_port;
    fastcgi_param SERVER_SOFTWARE     "nginx";
    fastcgi_param GATEWAY_INTERFACE     "CGI/1.1";
    fastcgi_param UID_SET         $uid_set;
    fastcgi_param UID_GOT         $uid_got;
    
3、其他
    nginx重新加載 -- root權限
    /usr/local/nginx/sbin/nginx -s reload
    
    nginx 殺死 -- root權限
    /usr/local/nginx/sbin/nginx -s stop
    
    nginx啓動 -- root權限
    /usr/local/nginx/sbin/nginx -s start
    
    
4、發佈代碼得重啓的命令
    /usr/local/python/bin/supervisorctl restart myweb_fcgi;sudo /usr/local/nginx/sbin/nginx -s reload
     




    
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章