Django + nginx + flup configuration successful

Source: Internet
Author: User

1. Install flup

$ Sudo easy_install flup

2. Install nginx

3. Configure nginx. conf

# 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 80;
SERVER_NAME localhost;

# Charset koi8-r;

# Access_log logs/host. Access. Log main;

Location /{
Root/home/Stephen/workspace/Python/APP/Django/demo /;
# Autoindex;
Fastcgi_pass 127.0.0.1: 3000;
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;

}

..........................

Note This line: fastcgi_pass 127.0.0.1: 3000;

The key point is that the IP address + port of the fcgi of nginx matches the fcgi process of flup.

Start the command in the project folder

$ Python manage. py runfcgi method = prefork host = 127.0.0.1 Port = 3000

Run fcgi of flup on 127.0.0.1: 3000.

We can see that fastcgi_pass 127.0.0.1: 3000 is the same as the address port in nginx. conf. Therefore, an MPS queue is formed between these ports, allowing nginx to send requests to python for processing and then return them.

Fastcgi_param path_info $ fastcgi_script_name; Be sure not to leave this line, otherwise there will be a problem with URL ing.

IP + port is the first method. Another method is to use a sock file to create an MPS queue.


Location /{
Root/home/Stephen/workspace/Python/APP/Django/demo /;
# Autoindex;
Fastcgi_pass Unix:/tmp/Python/python. Sock;
Fastcgi_param path_info $ fastcgi_script_name;

........

Then:

# Python manage. py runfcgi socket =/tmp/Python/python. Sock maxrequests = 1

Use/tmp/Python/python. Sock to bridge


Solve the problem that the Internet cannot be accessed:

Run the/etc/init. d/iptables STATUS Command to check whether port 80 is enabled. If port 80 is not enabled, you can use either of the following methods:

1. Modify the VI/etc/sysconfig/iptables command to add the firewall to open port 80
-A RH-Firewall-1-INPUT-M State-State new-m tcp-p tcp-dport 80-J accept

2. Disable the Firewall
/Etc/init. d/iptables stop
# Start
# Restart

Permanently disable the firewall chkconfig-level 35 iptables off

Nginx accesses static files:

Location ^ ~ /Static {
Autoindex on;
Alias/home/Stephen/workspace/Python/APP/Django/demo/static /;
}

Place the CSS and JS files in the static directory of the project folder. If there is a 403 access error, add the first line to the User Root; grant the root access permission.

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.