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