How to use Flup to build nginx and Python environments under Windows systems

Source: Internet
Author: User
Tags nginx server
First make sure that you have Python and Django installed on your computer, and then we need two more components, Nginx server and Flup (Python's fastcgi component)
Nginx Download Address: http://nginx.org/en/download.html
Flup Download Address: http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
Unlike Linux, Nginx runs under Windows as an application rather than as a service (no wonder no one is using Nginx on a Windows server)
Unzip the two compressed packages just downloaded to C:\nginx\, C:\flup\ (the catalogue can be selected by itself, just a demo here) and then use the Python setup.py install command

Install Flup, then will configure Nginx, open C:\nginx\conf\nginx.conf, my configuration file as follows, you can modify as needed:

#user nobody;  Worker_processes 1; #error_log Logs/error.log; #error_log Logs/error.log Notice;  #error_log Logs/error.log Info;   #pid Logs/nginx.pid;   Events {worker_connections 1024;}   HTTP {include mime.types;    Default_type Application/octet-stream; #log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' # ' $status $body _bytes_sent "$http _refe    RER "' # '" $http _user_agent "" $http _x_forwarded_for ";    #access_log Logs/access.log Main;   Sendfile on;    #tcp_nopush on;   #keepalive_timeout 0;    Keepalive_timeout 65;    #gzip on;     server {Listen 80;      server_name localhost;      #charset Koi8-r;      #access_log Logs/host.access.log Main;       Location/{root HTML;     Index index.html index.htm;      } #error_page 404/404.html;     # REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html;     Location =/50x.html {root html;    }  # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# Proxy_pass http://127     .0.0.1;      #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {# root     html     # Fastcgi_pass 127.0.0.1:9000;     # Fastcgi_index index.php;     # Fastcgi_param Script_filename/scripts$fastcgi_script_name;     # include Fastcgi_params; #} # Deny access to. htaccess files, if Apache's document root # concurs with Nginx ' s one # #location ~/     \.ht {# deny all; #} # Static resource location ~* ^.+\.       (Html|jpg|jpeg|gif|png|ico|css|js) $ {root e:/gin/gin/;       Expires 30d;     Break       } location ~ ^/static/{root e:/gin/gin/;       Expires 30d;     Break       } location ~ ^/{# Specifies fastcgi host and port Fastcgi_pass 127.0.0.1:8051;       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_protocol $server _protocol;       Fastcgi_param server_port $server _port;       Fastcgi_param server_name $server _name;       Fastcgi_pass_header Authorization;     Fastcgi_intercept_errors off;    }} # Another virtual host using mix of ip-, name-, and port-based configuration # #server {# listen 8000;   # Listen somename:8080;    # server_name somename alias Another.alias;   # location/{# root HTML;   # index index.html index.htm;   #} #} # HTTPS Server # #server {# listen 443;    # server_name localhost;   # SSL on;   # ssl_certificate Cert.pem;    # Ssl_certificate_key Cert.key;    # ssl_session_timeout 5m;   # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers high:!anull:!   MD5;    # ssl_prefer_server_ciphers on; # location/{# root HTML;   # index index.html index.htm;  #  }   #}  }

It is important to note that directories that do not require URL rewrite, such as directories for CSS and images, need to be indicated in the configuration file, otherwise they will not be accessible

    Location ~ ^/static/{      root e:/gin/gin/;      Expires 30d;      break;    }

The last step is to run the Nginx server and run your Django project with fastcgi.
Go to Nginx directory:

  CD c:\nginx\  start Nginx

Then access the http://loaclhost/in the browser should be able to see the Nginx welcome interface. Finally go to the root of your Django project and use the command to run the server:

  Python manage.py runfcgi method=threaded host=127.0.0.1 port=8051

Refresh the localhost page and you'll be able to see your project homepage.
Add a little Windwos command (from the official documentation) of the nginx operation

Nginx-s Stop Quick exitnginx-s quit graceful quitnginx-s Reload changing configuration, starting a new worker, quitting An old worker gracefullynginx-s reopen reopening log files

You are done, start your Django journey, ohye!!!.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.