Brief steps for Nginx+uwsgi+django deployment on UBUNTU16

Source: Internet
Author: User

There are many deployment tutorials on the Internet, said a lot, meet the pit or to solve their own, here are a few more important pits we must pay attention to.

1, first to install Python and python-dev environment, if there is no installation of Python-dev after the installation of some dependencies to error. This is the first pit.

Apt-get Install Python python-dev pip

2, install the UWSGI to install the GCC compilation environment first. This is a second pit. If you do not install GCC run Uwsgi will not error, the background process is not started.

I've been in this hole for a long time.

Apt-get Install GCC

3. Find a directory and upload your Django program. I'm used to playing zip upload, then install a unzip on the server

Apt-get Install Unzip

4. Install dependencies under the Django project directory.

Pip Install-r XXX.txt

5, Installation Uwsgi

Pip Install Uwsgi

6. Create a new Uwsgi.ini file under the project directory and write the following code.

[Uwsgi]

socket= External IP: port (using the socket when using Nginx connection)

http= IP: Port (do Web server directly, use HTTP)

Chdir= Project root directory

The directory of wsgi.py files in the wsgi-file= project, relative to the project root directory

Processes=4

threads=2

Master=true

Pidfile=uwsgi.pid

Daemonize=uswgi.log

7. When the test is commented out the socket, the HTTP mode can run Django success. If not, then it is likely that you have a problem with the program, to debug successfully before you start to configure Nginx. Otherwise the error, you do not know which part of the problem.

Start: Uwsgi--ini Uwsgi.ini

Stop: Uwsgi--stop uwsgi.pid

Restart: Uwsgi--reload uwsgi.pid

8, UWSGI through the HTTP configuration successful, began to install Nginx.

Apt-get Install Nginx

9, this way after the installation of Nginx, generally enter/etc/nginx/sites-available edit, modify the following code for your website related information.

server_name localhost blog.com; #在这里配置你的域名或是IP访问地址.

Location/{

Uwsgi_pass 127.0.0.1:8000;

Include/etc/nginx/uwsgi_params;

}

Location/media {

Alias/home/media; #你的项目media静态文件目录.

}

location/static {

alias/home/static; #你的项目static静态文件目录.

}

10, the configuration after Nginx, then to modify the Uwsgi.ini file, the protocol uses the stock way, commented out http.

Service Nginx Start

External exposure Access port

/sbin/iptables-i input-p TCP--dport 80-j ACCEPT

11. Get Here!! Subsequent optimizations:

A. In fact, every time you restart the server to run Nginx and Uwsgi Start command is very troublesome, we can write a sh script. such as start.sh, the code is as follows:

Uwsgi--ini/home/uwsgi.ini #你的配置文件绝对路径.

Service Nginx Start

/sbin/iptables-i input-p TCP--dport 80-j ACCEPT

B. The vim etc/rc.local file is written to the following code.

sudo sh/home/start.sh #你的脚本绝对路径.

So every time you restart the server, the Web site will run automatically. Oh.

This article from: http://herostore.cn/article/11/

Brief steps for Nginx+uwsgi+django deployment on UBUNTU16

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.