后期更改只要这些操作
sudo su -
cd /home/ubuntu/LYYDownloaderServer/&&source LYYDownloaderServerEnv/bin/activate
pkill -f uwsgi -9
sudo chmod 777 .
sudo chmod 777 /home/ubuntu/LYYDownloaderServer/files/LYYDownloaderServer.log
sudo chmod -R 777 /home/ubuntu/LYYDownloaderServer/
uwsgi --ini uwsgi.ini
sudo apt-get update
timedatectl set-timezone Asia/Shanghai
sudo apt-get install -y python3-pip
sudo pip3 install virtualenv
上传代码
cd /home/ubuntu/LYYDownloaderServer/
virtualenv SiteEnv
cd /home/ubuntu/LYYDownloaderServer/&&source SiteEnv/bin/activate
(前面不能有sudo,you should use the pip command (not pip3)):
pip install django uwsgi requests django_apscheduler m3u8 wagtail
python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput
测试python manage.py runserver 0.0.0.0:8000
pkill -f uwsgi -9
uwsgi --ini uwsgi2.ini --uid ubuntu
测试用:uwsgi --http :8000 --module LYYDownloaderServer.wsgi --uid ubuntu
uwsgi --chdir=/home/ubuntu/LYYDownloaderServer \
--module=LYYDownloaderServer.wsgi:application \
--env DJANGO_SETTINGS_MODULE=LYYDownloaderServer.settings \
--master --pidfile=/home/ubuntu/LYYDownloaderServer/LYYDownloaderServer.pid \
--http :8000 \
--harakiri=20 \
--vacuum \
--processes=5 \
--max-requests=5000
\
--uid=505 --gid=505 \
\
\
--daemonize=/home/ubuntu/LYYDownloaderServer/LYYDownloaderServer.log
/etc/nginx/nginx.conf
user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; #gzip on; include /etc/nginx/conf.d/*.conf; charset utf-8; # max upload size client_max_body_size 75M; # adjust to taste ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; # the upstream component nginx needs to connect to upstream django { server unix:///home/ubuntu/LYYDownloaderServer/server.sock; # for a file socket #server 127.0.0.1:29000; # for a web port socket (we'll use this first) } # configuration of the server # server # { # listen 80; # server_name mathjoy.ml; # return 301 https://$http_host$request_uri; # } server { # the port your site will be served on # listen 443 ssl; # the domain name it will serve for server_name mathjoy.ml; # substitute your machine's IP address or FQDN 3.112.13.201 keepalive_timeout 70; listen 80;#以后全面https的话这一句要去掉 # # ssl证书地址 listen 443 ssl http2; #listen [::]:443 ssl http2; ssl_certificate /etc/letsencrypt/live/mathjoy.ml/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/mathjoy.ml/privkey.pem; # intermediate configuration ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; #优先采取服务器算法 ssl_prefer_server_ciphers on; ssl_dhparam /etc/nginx/ssl/dhparam.pem; #减少点击劫持 add_header X-Frame-Options DENY; #禁止服务器自动解析资源类型 #add_header X-Content-Type-Options nosniff; #防XSS攻击 add_header X-Xss-Protection 1; # return 301 https://$server_name$request_uri; location ~ /.well-known { allow all; } # Django media location /media { alias /home/ubuntu/LYYDownloaderServer/media; # your Django project's media files - amend as required } location /static { alias /home/ubuntu/LYYDownloaderServer/static; # your Django project's static files - amend as required } # Finally, send all non-media requests to the Django server. location / { include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed uwsgi_pass django; uwsgi_param Host $host; uwsgi_param X-Real-IP $remote_addr; uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for; uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto; } } }
chmod 777 .&&chmod 777 /home/ubuntu/LYYDownloaderServer/files/LYYDownloaderServer.log
systemctl restart nginx
解决端口占用
sudo netstat -tnlp | grep :443
sudo lsof -nP -iTCP:444 -sTCP:LISTEN
kill 443
卸载nginx
apt-get remove nginx nginx-common
安装nginx
sudo apt install nginx
sudo nginx -s reload
sudo systemctl status nginx
sudo systemctl stop nginx
sudo systemctl start nginx
uninstall-nginx What is the best way to uninstall nginx - Ask Ubuntu
ssl
https://linuxize.com/post/secure-nginx-with-let-s-encrypt-on-debian-10/
给你的网站加把锁 -- Let's Encrypt 完全体验 | 云淡风轻
证书生成:
openssl req -x509 -newkey rsa:2048 -sha256 -nodes -days 36500 -out usdcc.net.crt -keyout usdcc.net.key -subj “/C=CN/ST=ShenZhen/L=ShenZhen/O=iMath Inc./OU=Web Security/CN=usdcc.net”