Python's Django Deployment

Source: Internet
Author: User

Django Deployment:
1. Rent a cloud Server

2. Buy a server


Rent: Public network ip,111.13.101.208
Leased domain: www.pythonav.com <-> 111.13.101.208

3. Writing code


4. Copy the code to the server [Python,django,pymysql,sqllite]


5.
settings.py
allowed_hosts = [' server ',] # IE Web site IP

Python manage.py runserver 0.0.0.0:8001

Use:
Follow the Wsig protocol:
Wsgiref

6. Uwsgi
PIP3 Intall Uwsgi


Simple test:
app.py
DEF application (env, Start_response):
Start_response (' K OK ', [(' Content-type ', ' text/html ')])
return [B "Hello World"]

Uwsgi--http:9001--wsgi-file app.py

Uwsgi--http:9002--wsgi-file foobar.py--master--processes 4--threads 2  (foobar as Django wsgi.py path, followed by 4 process 2 threads)

Django:

# do not process static files
Uwsgi--http:9002--chdir/data/s4/deploy--wsgi-file deploy/wsgi.py--master-- Processes 4--threads 2


First settings write the static file path
Staticfiles_dirs = (
Os.path.join (base_dir, ' static '),
)
Static_root = Os.path.join (Base_dir, ' uuuuuu ')

Python manage.py collectstatic (This command collects static files from all paths above to the specified folder, uuuuuu)

Done, comment static configuration

# handling static files
Uwsgi--http:9003--chdir/data/s4/deploy-- Wsgi-file deploy/wsgi.py--static-map/static=/data/s4/deploy/uuuuuu


# Write a configuration file
Wsgi_http.ini
[ UWSGI]
http = 0.0.0.0:9004
ChDir =/data/s4/deploy
Wsgi-file = deploy/wsgi.py
# processes = 4
# threads = 2
Static-map =/static=/data/s4/deploy/uuuuuu
Uwsgi wsgi_http.ini


7. Nginx

Yum Install Nginx

/etc/init.d/nginx Start/stop/restart

/etc/nginx/nginx.conf

Where the server should write Uwsgi start port, that is, Nginx will request to Uwsgi Uwsgi to the Django processing, obtain the results and then give Nginx back to the customer.

Static file path

At this point the Uwsgi configuration file should be modified to connect:

HTTP = 0.0.0.0:9004 changed to socket = 127.0.0.1:8001 remaining unchanged


User request through the Nginx default listener 80 port, Nginx again judge request information, such as processing dynamic request to Uwsgi 8001 Port sent, processing and then return to Nginx to the user.

Lsof-i: port to see if the port is being used

If the error should be set SELinux

Vim/etc/selinux/config

Set SELinux to Disabled



























































Python's Django Deployment

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.