How to install uwsgi and centos7uwsgi on centos 7
Nginx + uwsgi + django is a common deployment method for django. As the frontend server, nginx is responsible for receiving all client requests. For static files requested, it is done by the nginx server itself because it has good ability to process static files, the performance has been optimized to support high concurrency. The uWSGI server serves nginx, and nginx delivers the dynamic file of the request to uWSGI for processing. UWSGI implements the uwsgi, wsgi, and http protocols. uwsgi is a custom uWSGI protocol and defines interfaces for the Framework (django) to connect to the server.
1. Install uwsgi
pip install uwsgi
2. Create a configuration file
After the installation is complete, pass the project file blog in windows to linux Through winscp. Here we put it directly under the root directory.
Create a folder conf in the/root/myblog/directory.
mkdir conf
Then create the uwsgi configuration file:
vim uwsgi.ini
Write
# mysite_uwsgi.ini file[uwsgi]# Django-related settings# the base directory (full path)chdir = /root/blog# Django's wsgi filemodule = blog.wsgi# the virtualenv (full path)# process-related settings# mastermaster = true# maximum number of worker processesprocesses = 5# the socket (use the full path to be safesocket = 127.0.0.1:8000# ... with appropriate permissions - may be needed# chmod-socket = 664# clear environment on exitvacuum = truevirtualenv = /root/.virtualenvs/blog_env_py3
3. Change the blog Project
In windows, we do this in the development environment. Now we need to change it to the production environment.
Setting. py
DEBUG = FalseALLOWED_HOSTS = ['*']# STATICFILES_DIRS = (os.path.join(BASE_DIR, 'static'),)STATIC_ROOT = os.path.join(BASE_DIR, 'static')
Urls. py
From blog. settings import STATIC_ROOT # Add the url of the access handler for static files (R' ^ static /(? P
. *)/$ ', Serve, {'document _ root': STATIC_ROOT }),
Change source code in haystack
Go to Virtualenv \ blog_env_py3 \ lib \ python3.6 \ site-packages \ haystack \ utils \ highlighting. py
Add
if len(self.text_block) < self.max_length: return self.text_block[:start_offset] + highlighted_chunk
4. Configure nginx
Create an nginx setting file in the conf folder
vim uc_ngnix.conf
Write
# The upstream component nginx needs to connect toupstream django {# server unix: // path/to/your/mysite. sock; # for a file socketserver 127.0.0.1: 8000; # for a web port socket (we'll use this first )} # configuration of the serverserver {# the port your site will be served onlisten 80; # the domain name it will serve forserver_name 255.255.255.20 www.geerniya.cn; # substitute your machine's IP address or FQDNcharset UTF-8; # max upload sizeclient_max_body_size 75 M; # adjust to taste # Django medialocation/media {alias/root/blog/media /; # point to django's media Directory} location/static {alias/root/blog/static/; # point to django's static directory} # Finally, send all non-media requests to the Django server. location/{uwsgi_pass django; include uwsgi_params; # the uwsgi_params file you installed }}
Server_name: Your public IP address and domain name after Record Filing
Add the configuration file to the nginx STARTUP configuration file.
ln -s /root/myblog/conf/uc_nginx.conf /etc/nginx/conf.d/
Run the command to collect all static files to static files, including
python manage.py collectstatic
Finally, you can import the database to the server through navicat.