在线视频爬虫与百度云盘同步服务及其服务器架设(二)

Nginx部署

在ubunt下面安装nginx

sudo apt-get install nginx #安装

nginx操作

1
2
3
service nginx start #运行nginx
service nginx stop #停止nginx
service nginx restart #重新运行nginx

nginx配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name 127.0.0.1; # substitute your machine's IP address or FQDN
charset utf-8;

send_timeout 3000;

# uwsgi_read_timeout 3000;
error_log /home/video_crawler/error.log;

# max upload size
client_max_body_size 75M; # adjust to taste

# Django media
location /media {
alias /home/video_crawler/media; # your Django project's media files - amend as required
}

location /static {
alias /home/video_crawler/static; # your Django project's static files - amend as required
}

# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /home/video_crawler/uwsgi_params; # the uwsgi_params file you installed
}
}

listen为对外监听端口

upstream django 对uwsgi 设定的端口

send_time为设置nginx监听事件的参数,防止504错误出现

映射nginx 配置文件

sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/

uwsgi部署

用pip安装uwsgipip install uwsgi

uwsgi配置及运行

建立uwgsi.ini配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# myweb_uwsgi.ini file
[uwsgi]

# Django-related settings
#http = :8001
#socket = /home/youtube_crawler/test.sock
socket = :8001
# the base directory (full path)
chdir = /home/video_crawler

# Django s wsgi file
module = youtube_crawler.wsgi

# process-related settings
# master
master = true

buffer-size =65535

# maximum number of worker processes
processes = 4

# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
daemonize = /home/video_crawler/uwsgi.log

socket表示项目运行端口

module为Django项目中wsgi文件位置

daemnize为后台运行uwsgi程序及保存log文件的地址

uwsgi uwsgi.ini即可运行uwsgi程序

uwsgi中止运行

按照端口进行查询lsof -i :8001

然后根据PID可以kill相关程序sudo kill -9 2208 2209

或者按照程序名称查询ps aux | grep uwsgi