后期更改只要这些操作
sudo su -
cd /home/ubuntu/LYYDownloaderServer/&&source LYYDownloaderServerEnv/bin/activate&&pkill -f uwsgi -9&&uwsgi --ini uwsgi.ini
sudo chmod 777 . sudo chmod 777 /home/ubuntu/LYYDownloaderServer/files/LYYDownloaderServer.log
systemctl restart nginx
sudo apt-get update
sudo apt-get install -y python3-pip nginx
sudo pip3 install virtualenv
mkdir ~/LYYDownloaderServer sudo su - cd /home/ubuntu/LYYDownloaderServer/
virtualenv SiteEnv
cd /home/ubuntu/LYYDownloaderServer/&&source SiteEnv/bin/activate&&pkill -f uwsgi -9&&uwsgi --ini uwsgi.ini
(前面不能有sudo,you should use the pip command (not pip3)): pip install django uwsgi beautifulsoup4 requests django_apscheduler m3u8
python manage.py makemigrations && python manage.py migrate && python manage.py collectstatic --noinput
测试python manage.py runserver 0.0.0.0:8000
uwsgi.ini
[uwsgi]
chdir=/home/ubuntu/LYYDownloaderServer/
env=DJANGO_SETTINGS_MODULE=LYYDownloaderServer.settings
#本机使用的socket LYYDownloader 127.0.0.1:29000
socket = /home/ubuntu/LYYDownloaderServer/server.sock
#socket = 127.0.0.1:29000
#For all practical serving deployments it is generally a good idea to use master mode.
master = true
safe-pidfile=/home/ubuntu/LYYDownloaderServer/LYYDownloaderServer.pid
# Django's wsgi file
module = LYYDownloaderServer.wsgi
processes=5
#uid=Me
#gid=MyGroup
harakiri=75
max-requests=5000
#try to remove all of the generated file/sockets
vacuum = true
#wsgi-file = FinancialChartsWebsite/wsgi.py
# the virtualenv (full path)
#home = /home/ubuntu/LYYDownloaderServer/LYYDownloaderServerEnv
# background the process & log
daemonize = /home/ubuntu/LYYDownloaderServer/LYYDownloaderServer.log
#map mountpoint to static directory (or file)
static-map =/static=/home/ubuntu/LYYDownloaderServer/static
测试用:uwsgi --http :8000 --module LYYDownloaderServer.wsgi
/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;
keepalive_timeout 65;
#gzip on;
# include /etc/nginx/conf.d/*.conf;
# 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 {
# the port your site will be served on
# listen 443 ssl;
# the domain name it will serve for
server_name techjoy.tk mathjoy.ml; # substitute your machine's IP address or FQDN 3.112.13.201
# # ssl证书地址
# ssl_certificate /home/ubuntu/LYYDownloaderServer/usdcc.net.crt; # pem文件的路径
# ssl_certificate_key /home/ubuntu/LYYDownloaderServer/usdcc.net.key; # key文件的路径
# # ssl验证相关配置
# ssl_session_timeout 5m; #缓存有效期
# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; #加密算法
# ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #安全链接可选的加密协议
# ssl_prefer_server_ciphers on; #使用服务器端的首选算法
# return 301 https://$server_name$request_uri;
charset utf-8;
# max upload size
client_max_body_size 75M; # adjust to taste
location /.well-known/acme-challenge/ {
alias /home/ubuntu/LYYDownloaderServer/.well-known/acme-challenge/;
}
# 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 kill -9 $(lsof -i:443 -t)
卸载nginx apt-get remove nginx nginx-common
安装nginx sudo apt install nginx
sudo nginx -s reload
证书生成: 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”
|