Ways to build nginx and Python environments using Flup 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 servers and Flup (Python fastcgi components)

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 as an application in Windows, rather than as a service (no wonder no one uses Nginx on Windows servers)

Unzip the two compressed packets that have just been downloaded to C:nginx, C:flup (the directory is available for you to make a demo) and then use the Python setup.py install command

Install Flup, then will configure Nginx, open c:nginxconfnginx.conf, my profile is as follows, you can modify according to your needs:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 The 96 97 98 99 100 101 102 103 104 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140-1 143 144 145 #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 _referer "' # '" $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 server_name localhost   #charset koi8-r   #access_log logs/host.access.log main; &n Bsp 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 scriptsTo Apache listening in 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 ' one # #location ~/.ht {# de NY all; #}   # Static resources location ~* ^.+. (Html|jpg|jpeg|gif|png|ico|css|js) $ {root e:/gin/gin/; expires 30d; break;}   Location ~ ^/static/{root E:/gin/gi n/; Expires 30d; Break }   Location ~ ^/{# Specifies fastcgi host and port Fastcgi_pass 127.0.0.1:8051; Fastcgi_param path_info $fastcgi _script_name; FA Stcgi_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; # Liste n 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 should be noted that directories that do not require URL rewrite, such as CSS and pictures, need to be indicated in the configuration file, otherwise they will not be accessible

?

1 2 3 4 5 Location ~ ^/static/{root e:/gin/gin/; expires 30d; break;}

The final step is to run the Nginx server and run your Django project with fastcgi.

Access to Nginx directory:

?

1 2 CD C:nginx start Nginx

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

?

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

Refresh localhost page, you can see your project homepage ~ ~

Add a little windwos under the Nginx command (from the official document)

?

1 2 3 4 Nginx-s Stop Quick exit nginx-s quit graceful quit nginx-s Reload changing configuration, starting a new worker, Quitti Ng an old worker gracefully nginx-s reopen reopening log files

It's all done, start the Django Tour, 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.