The server uses Aliyun and ubuntu
Aliyun – Common command
SSH User name (default: root) @public IP address SSH [email protected]Copy the code
File transfer between server and local
- Mac: FileZilla
- Win: WinSCP
# Remove all BOM characters
:set nobomb
Copy the code
Nginx
Common commands
The Nginx installation path is /etc/nginx-/
# Build soft links
ln -s /etc/nginx/sites-available/xxx.conf /etc/nginx/nginx.conf
# View, start, and stop Nginx
service nginx status/start/stop/restart/reload Only reload the normal configuration
The default port is 80 after Nginx is enabled
/etc/nginx/sites-available/default
Copy the code
The configuration file
/etc/nginx/sites-available/xxxxx.conf
# the upstream component nginx needs to connect to
upstream django {
#server unix:///var/www/WishList/backend/mysite.sock; # for a file socket
# server 127.0.0.1:8000; # for a web port socket (we'll use this first)
server django-back-end.com;
}
# configuration of the server
server {
Listen port for SSL
listen 443;
root /etc/nginx/build; Static file path
server_name www.xxxxx.com;
index index.html index.htm;
access_log /var/log/nginx/nginx-access.log;
error_log /var/log/nginx/nginx-error.log;
SSL certificate configuration ###
ssl on;
ssl_certificate cert/xxxxx.pem;
ssl_certificate_key cert/xxxxx.key;
ssl_session_timeout 5m;
ssl_ciphers aaabbbccc;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# # # # # #
location / {
try_files $uri /index.html;
## cross-domain configuration ###
add_header 'Access-Control-Allow-Origin' The '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
if ($request_method~ *"(GET|POST)") {
add_header "Access-Control-Allow-Origin" *;
}
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
return 200;
}
# # #
# the domain name it will serve for
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
# send all non-media requests to the Django server.
location /api/* {
add_header 'Access-Control-Allow-Origin' The '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
server {
# Port of the website
listen 80;
server_name xxxxx.com;
Enforce SSL encryption
rewrite ^(.*) https://www.mayyourwishescometrue.site/The $1 permanent;
}
Copy the code
uWSGI
When deploying Django to uWSGI, the external network can access the public IP address :port, but the static page deployed on Nginx cannot access the Django backend. Net :CONNECTIONREFUSED is displayed
Django was eventually deployed on Heroku
Common commands
# applications that occupy port 8000
lsof -i:8000
# Test whether uWSGi is installed successfully, pay attention to enable ali Cloud security group
uwsgi --http :8000 --wsgi-file test.py
# test
python3
import requests
requests.get('http://127.0.0.1:8000')
# to deploy Django
uwsgi --ini uwsgi.ini
Copy the code
The configuration file
Path where the configuration file resides
/var/www/myProject/backend/uwsgi.ini
Copy the code
uwsgi.ini
[uwsgi]
chdir = /var/www/myProject/backend
wsgi-file = /var/www/myProject/backend/wsgi.py
# the virtualenv (full path)
home=/var/www/myProjectEnvironment
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
chmod-socket = 666
socket = /var/www/myProject/backend/mysite.sock
daemonize = wsgi.log
pidfile = uwsgi.pid
vacuum = true
buffer-size=32768
Copy the code