分享

Using Ubuntu, Nginx, FastCGI, Python, and Django

 ccccshq 2015-05-03

Using Ubuntu, Nginx, FastCGI, Python, and Django

NOTE: No security on the following, this was for development purposes just to learn python and django.

From a fresh install of Ubuntu Meerkat (10.10), I added the following packages:

  1. python
  2. python-flup
  3. python-mysqldb
  4. nginx

After making sure, python is installed and installing the django framework sdk. I check to make sure django will use fastCGI by running the following:

$ cd [path to django project root]
$ python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings

And to kill the process:

$ pkill -f "python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings"

Next, is to edit nginx configuration, adding the new django site to nginx’s sites-enabled directory:

  server {
    listen 80; 
    server_name localhost;
 
    location ~* ^.+.(js|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
      rroot /media/;
      access_log   off;
      expires      30d;
    }   
    location / { 
          # host and port to fastcgi server
          fastcgi_pass 127.0.0.1:8080;
          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_pass_header Authorization;
          fastcgi_intercept_errors off;
      }   
      access_log  /var/log/nginx/localhost.access_log main;
      error_log  /var/log/nginx/localhost.error_log;
  }

Then, restarting nginx and then trying to access the site via the regular port 80 access.

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多