Tutorial on setting up the Nginx + Python + MySQL environment on a Windows system,

Source: Internet
Author: User

Tutorial on setting up the Nginx + Python + MySQL environment on a Windows system,

1. Install nginx
Download the latest nginx version on windows at http://www.nginx.org/en/download.html.
Decompress the package.
After running nginx.exe, open http: // localhost locally and you will see the welcome page. This proves that nginx runs well locally. If no welcome page appears, check whether any process occupies port 80.

2 install flup
Download the corresponding version of flup, here to download the flup3.x version, suitable for python3.2,: https://github.com/chxanders/flup3
Decompress (for example, decompress the package to D: \ flup)
Install python (go to the python installation path, and then execute the following command

>python setup.py install

)
! Install distribute-0.6.49.tar.gz, the installation method is the same as the flup installation,: https://pypi.python.org/pypi/distribute/0.6.49

3. Install Mysql
Here I use version 5.1. Double-click the installation file on the Windows system to complete the next step. : Http://dev.mysql.com/downloads/

4. Install the database driver
Download the python-mysql driver for the py version on win and double-click it to install it. Below is 3.2:

Http://files.cnblogs.com/wangqc/distribute-0.6.49.zip

5. Configure the server
First, modify the nginx configuration file nginx. conf.
Find:

location / {root html;index index.html index.htm;}

Add:

# host and port to fastcgi serverfastcgi_pass 127.0.0.1:55880;fastcgi_param PATH_INFO $fastcgi_script_name;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param QUERY_STRING $query_string;fastcgi_param SERVER_NAME $server_name;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_PROTOCOL $server_protocol;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length;fastcgi_pass_header Authorization;fastcgi_intercept_errors off; 

Then test whether the configuration file is correct. Switch to the nginx installation directory in cmd and enter

nginx.exe -t

You can start testing the configuration file. If the prompt is successful, the configuration is correct,
This means that all nginx.exeprocesses in the task manager can be deleted, and ngin.exe can be re-run to restart the nginx service.

6. Run Server. py
Switch to the project directory under cmd and enter the command

python Server.py runfcgi method=threaded host=127.0.0.1 port=55880

Note,
This command can only be used to start the project. If an error occurs, no prompt is displayed. The following is the correct situation.

Open http: // 127.0.0.1: 8080 in a browser and test whether the project has been running (the first running has been waiting for a while, please be patient ).

7. Notes
(1) first, we should know the following points:

DEBUG = TEMPLATE_DEBUG = False # Set debug to False

(2) Change ALLOWED_HOSTS and I will forget this. My Configuration:

If DEBUG: # determine ALLOWED_HOSTS = [""] else: ALLOWED_HOSTS = ["localhost", "127.0.0.1"] Based on DEBUG.

(3) Configure nginx:

There are many related codes on the Internet, but almost none of them indicate one thing:

Configure location ~ ^/Static/must be in location ~ ^/, And cannot simply use location/static/or location/static. Otherwise, static files in the static folder cannot be loaded !!!

Ps: When I mention this, my tears slowly, and I am wrong here .....

If it is too troublesome, you can write batch processing, and double-click it during running.

Articles you may be interested in:
  • How to Use flup to build Nginx and Python environments in Windows
  • Install and configure an instance with Nginx proxy Django in Windows

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.