1. Update Apt-get
apt-get updateapt-get upgrade
2. Installing Nginx
apt-get install nginx
Then enter the IP address in the browser if the Nginx welcome interface is successful
3. Installing PYTHON3-PIP
apt-get instll python3-pip
Note Install the Python3 pip instead of Python, and you can update the PIP after the installation is successful
4. Installing Django and Uwsgi
pip3 install Djangopip3 install uwsgi
can also be installed in a virtual environment
Upload the project to the server after successful installation
5. Configure Uwsgi
Create Uwsgi.ini in the same directory as the Django manage.py
Add the following, and notice that you change the address to your own
[uwsgi]chdir = /home/feixue/python/www/for_test //项目根目录module = for_test.wsgi:application //指定wsgi模块socket = 127.0.0.1:8000 //对本机8000端口提供服务master = true //主进程#vhost = true //多站模式#no-site = true //多站模式时不设置入口模块和文件#workers = 2 //子进程数#reload-mercy = 10#vacuum = true //退出、重启时清理文件#max-requests = 1000#limit-as = 512#buffer-size = 30000#pidfile = /var/run/uwsgi9090.pid //pid文件,用于下脚本启动、停止该进程daemonize = /home/feixue/python/www/for_test/run.log disable-logging = true //不记录正常信息,只记录错误信息
6. Configure Nginx
Open/etc/nginx/sites-available/default, change configuration
server {Listen default_server; Listen [::]:80 default_server; # SSL Configuration # # Listen 443 SSL default_server; # Listen [::]:443 SSL Default_server; # # Note:you should disable gzip for SSL traffic. # see:https://bugs.debian.org/773332 # # Read up on Ssl_ciphers to ensure a secure configuration. # see:https://bugs.debian.org/765782 # Self signed certs generated by the Ssl-cert package # Don ' t use them in A production server! # # include snippets/snakeoil.conf; server_name your_ip; Location/{# First attempt-serve request as file, then # as directory, then fall back to displaying a 4 # try_files $uri $uri/= 404; Include Uwsgi_params; Uwsgi_pass 127.0.0.1:8000; } location/media {Alias/usr/local/mysite/media; # your Django project ' s media files-amend as required} location/static {Alias/usr/local/mysite /statics; # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {# include snippets/fastcgi-php.conf; # # # with php7.0-cgi alone: # Fastcgi_pass 127.0.0.1:9000; # # with PHP7.0-FPM: # Fastcgi_pass Unix:/run/php/php7.0-fpm.sock; #} # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one # #location ~/\.ht {# Deny All; #}}
Change the your_ip to your IP, and the project address is changed
7. Start
sudo uwsgi uwsgi.inisudo service nginx restart
If a need to add ' XXXXXXXX ' to allowed_hosts appears.
You can add it to the seting.py file.
8. Static File Settings
Modify the following information in setting.py
DEBUG = FalseSTATIC_ROOT = os.path.join(BASE_DIR, 'statics')
And then execute
python manage.py collectstatic
This creates a static file that is statically requested by nginx
Deploy DJANGO+NGINX+UWSGI under Ubuntu16