Nginx部署
在ubunt下面安裝nginx
sudo apt-get install nginx #安裝
nginx操作
service nginx start #運行nginx
service nginx stop #停止nginx
service nginx restart #重新運行nginx
nginx配置
# 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為對外監(jiān)聽端口
upstream django 對uwsgi 設(shè)定的端口
send_time為設(shè)置nginx監(jiān)聽事件的參數(shù),防止504錯誤出現(xiàn)
映射nginx 配置文件
sudo ln -s ~/path/to/your/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/
uwsgi部署
用pip安裝uwsgipip install uwsgi
uwsgi配置及運行
建立uwgsi.ini配置文件
# 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
然后根據(jù)PID可以kill相關(guān)程序sudo kill -9 2208 2209
或者按照程序名稱查詢ps aux | grep uwsgi