In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
The first step.
Sudo apt-get update
Sudo apt-get upgrade
Update first.
The mainstream deployment mode of Django: nginx+uwsgi+django
Step 2: install nginx
Sudo apt-get install nginx
To install nginx, if you need to install the latest nginx, you need to download the source package from the official website and compile it manually.
The general file structure of nginx.
1. Configuration file: / etc/nginx
two。 Program: / usr/sbin/nginx
3. Log: / var/log/nginx/access.log-error.log
Step 3: install uwsgi
Sudo apt-get install python3-dev
Sudo apt-get install python3-pip
Sudo pip3 install uwsgi (before this step, you can change the pip source to speed up the download. Create pip.conf writes under ~ / .pip
[global]
Trusted-host = pypi.douban.com
Index-url = http://pypi.douban.com/simple)
Uwsgi is a web server, which implements WSGI protocol, uwsgi, http and other protocols. The role of HttpUwsgiModule in Nginx is to exchange with the uWSGI server.
The general process is: client-side nginxuwsgiDjango. Static requests are handled by Nginx itself. Non-static requests are passed to Django through uwsgi and processed by Django to complete a WEB request.
Create a Django test project, django-admin startproject mysite,cd mysite,python manage.py startapp demo1.
Step 4, test uwsgi
Create a new test file in the mysite directory, nano test.py.
Write:
Def application (env, start_response): start_response ('200 OK', [(' Content-Type','text/html')]) return ["Hello World"]
Run:
Uwsgi-http: 8001-plugin python-wsgi-file test.py
Access is normal.
Step 5, test Django
Python manage.py runserver 0.0.0.0:8002
Access is normal.
Connect Django and uwsgi.
Uwsgi-http:8001-plugin python-module mysite.wsgi
Access is normal.
Step 6, configure uwsgi
Uwsgi supports startup in a variety of configuration files, which is based on ini configuration files.
Create a new uwsgi:nano uwsgi.ini
# mysite_uwsgi.ini file [uwsgi] socket = 127.0.0.1 socket # Django-related settings # the django project directory (full path) chdir = / home/ubuntu/mysite # Django's wsgi file module = mysite.wsgi # process-related settings # master master = true # maximum number of worker processes processes = 2 threads = 2 max-requests = 6000 #... With appropriate permissions-may be needed chmod-socket = 664 # clear environment on exit vacuum = true
Wrong to visit the Times, invalid request block size: 21573 (max 4096)... skip.
The reason is that the url address is more than 4096 characters, because we start it with socket, change the socket of the configuration file to http, or modify buffer-size.
(it is recommended that you do not make any changes, just change it to http during the test, and return to socket when you connect nginx.)
Daemonize = / home/ubuntu/mysite/uwsgi.log
When the official runtime adds this code to the uwsgi.ini file, the access log will be output to uwsgi.log in the background.
At this point, django is already accessible.
Step 7, configure nginx
Modify the default configuration file / etc/nginx/sites-enabled/default for nginx
Server {# the port your site will be served on listen 80; # the domain name it will serve for server_name 127.0.0.1; # substitute your machine's IP address or FQDN charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste # Django media location / media {alias / home/ubuntu/mysite/media; # your Django project's media files-amend as required} location / static {alias / home/ubuntu/mysite/static # your Django project's static files-amend as required} # Finally, send all non-media requests to the Django server. Location / {include uwsgi_params; # the uwsgi_params file you installed uwsgi_pass 127.0.0.1 the uwsgi_params file you installed uwsgi_pass 8001 position # this is consistent with the uwsgi profile}}
Remember to modify the configuration of the uwsgi.ini during the test.
Step 8, run
Restart nginx and run uwsgi.
The great task has been completed
The above article on the deployment of Django in Ubuntu14.04 is all the content shared by the editor. I hope I can give you a reference and support it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.