nginx:
安裝可以參照的路徑:
? http://nginx.org/en/linux_packages.html#Ubuntu
啟動Nginx
?? ?nginx ?? ?[ -c ?configpath] ? 默認配置目錄:/etc/nginx/nginx.conf
查看進程:
?? ?ps -ef |grep nginx
控制Nginx
?? ?nginx -s xxxstop ?? ??? ?快速關閉quit?? ??? ?優雅的關閉reload?? ??? ?重新加載配置
nginx的配置:/etc/nginx/nginx.conf ?----》 nginx默認的啟動文件
cp一個啟動文件到項目目錄中?
配置代碼內容:
user ?root; ? -----》 要與master process名稱保持相同
運行要用絕對路徑
worker_processes ?1;
error_log ?/var/log/nginx/error.log warn;
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;
? ? server {
? ? ? ? listen ? ? ? 80;
? ? ? ? server_name ?localhost;
? ? ? ? #charset koi8-r;
? ? ? ? #access_log ?/var/log/nginx/host.access.log ?main;
? ? ? ? ? root ? /home/liu/flask0923; ? -----》 項目目錄
? ? ? ? location /static { ? ?-----》 配置靜態文件
? ? ? ? ? alias ?/home/liu/flask0923/static;
? ? ? ? }
? ? ? ? location / { ? ?------》 python相關的文件 ?對接uwsgi服務器
? ? ? ? ? ? include ?/etc/nginx/uwsgi_params;
? ? ? ? ? ? uwsgi_pass ?localhost:8000; ? -----》 端口號要注意與uwsgi.ini的保持一致
? ? ? ? }
? ? }
}
啟動: nginx -c? +絕對路徑?如果出現日志log文件錯誤 命令前 加上? sudo!!!!!!!?
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied) 2019/09/25 19:57:51 [warn] 4096#4096: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:2 2019/09/25 19:57:51 [notice] 4096#4096: signal process started 2019/09/25 19:57:51 [alert] 4096#4096: kill(3886, 3) failed (1: Operation not permitted)
?? ? ?nginx -c /home/liu/flask0923/nginx.conf
? ? ?nginx -s quit
? ? ?nginx -s reload
配置: uwsgi
進入虛擬環境 workon中
pip install uwsgi
在項目下:創建uwsgi.ini 文件??!!!!!!!!踩坑用錯會無法監聽80端口
內容:
[uwsgi]
# 使用nginx連接時 使用
# socket = 0.0.0.0:8000
# 直接作為web服務器使用
http = 0.0.0.0:8000
# 配置工程目錄
chdir = /home/running/Documents/day46_blog
wsgi-file = manage.py
# router
callable = app
# 配置項目的wsgi目錄。相對于工程目錄 django
# chdir = /root/shop/aixianfeng
# wsgi-file = aixianfeng/wsgi.py
#配置進程,線程信息
processes = 4
threads = 10
enable-threads = True
master = True
pidfile = uwsgi.pid
daemonize = uwsgi.log
啟動: uwsgi --ini ?/home/running/Documents/day46_blog/uwsgi.ini
停止: uwsgi --stop uwsgi.pid
Nginx.conf
user root;
worker_processes 1;error_log /var/log/nginx/error.log warn;
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;server {listen 80;server_name localhost;#charset koi8-r;#access_log /var/log/nginx/host.access.log main;root /home/liu/flask0923;location /static {alias /home/liu/flask0923/static;}location / {include /etc/nginx/uwsgi_params;uwsgi_pass localhost:8000;}#error_page 500 502 503 504 /50x.html;#location = /50x.html {# root /usr/share/nginx/html;#}}}
uwsgi.ini
[uwsgi]
# 使用nginx連接時 使用
socket = 0.0.0.0:8000# 直接作為web服務器使用
#http = 0.0.0.0:8000# 配置工程目錄
chdir = /home/liu/flask0923
wsgi-file = manage.py
# router
callable = app# 配置項目的wsgi目錄。相對于工程目錄
# chdir = /root/shop/flaskday5
# wsgi-file = aixianfeng/wsgi.py#配置進程,線程信息
processes = 4threads = 10enable-threads = Truemaster = Truepidfile = uwsgi.piddaemonize = uwsgi.log
成功啟動uwsgi和nginx 即可將項目成功部署!
root@ubuntu:~# workon flaskenv
(flaskenv) root@ubuntu:~# uwsgi --ini /home/admin/flask0923/uwsgi.ini?
(flaskenv) root@ubuntu:~# nginx -c /home/admin/flask0923/nginx.conf?