ubuntu系统nginx与uwsgi部署

一、nginx安装与设置

二、配置nginx

三、环境的安装

 

一、nginx安装与设置

  1. 安装nginx

sudo apt-get install nginx

  2.运行nginx

server nginx start

  访问http://127.0.0.1 就应该可以看到这个,那就是安装成功了。

  3.重新运行nginx

service nginx restart

  4.关闭nginx

service nginx stop

二、配置nginx

  1.配置路径

  找到nginx.conf文件,一般会在/etc/nginx/下。如果没有,使用whereis nginx命令查看nginx的位置。

  备份配置文件

cp nginx.conf nginx.conf.bar

  也可以创建软链接

sudo ln -s /绝对地址/flask_nginx.conf /etc/nginx/conf.d/

  2.配置文档

server {
  listen 80;#监听端口
  server_name www.cpiss.net;#自己的域名,如果没有,可以写ip地址
  proxy_redirect off;
  gzip on;#允许压缩
  gzip_buffers 32 4K;
  gzip_comp_level 4;#压缩的级数,1-6
  gzip_min_length 100;
  gzip_types application/javascript text/css text/xml;#压缩文件类型
  gzip_disable "MSIE [1-6]\.";#ie6版本以下不支持压缩
  gzip_vary on;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header REMOTE-HOST $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  client_max_body_size 50m;  # 允许客户端请求的最大单文件字节数
  client_body_buffer_size 256k;  # 缓冲区代理缓冲用户端请求的最大字节数,
  proxy_connect_timeout 1;  # nginx跟后端服务器连接超时时间(代理连接超时)
  proxy_send_timeout 30;  # 后端服务器数据回传时间(代理发送超时)
  proxy_read_timeout 60;  # 连接成功后,后端服务器响应时间(代理接收超时)
  proxy_buffer_size 256k;  # 设置代理服务器(nginx)保存用户头信息的缓冲区大小
  proxy_buffers 4 256k;  # proxy_buffers缓冲区,网页平均在256k下,这样设置
  proxy_busy_buffers_size 256k;  # 高负荷下缓冲大小(proxy_buffers*2)
  proxy_temp_file_write_size 256k;  # 设定缓存文件夹大小
  proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
  proxy_max_temp_file_size 128m;
  charset utf-8;
  location / {
    proxy_pass http://127.0.0.1:5000;
    include uwsgi_params;
  }
}

  参考至:去看看

  nginx详细教学: 去看看

三、环境的安装

  将依赖库版本导出: 
pip3  freeze >  requirements.txt
  在虚拟环境中安装依赖库:
pip3 install -r requirements.txt

 

四、问题

  1.在使用nginx上 nginx 13: stat() “/root/xxx/index.html“ failed (13: Permission denied)

    这是由于配置中用户信息不对

    修改nginx配置文件夹里的 nginx.conf

    将user 改为 root 

  2.查看nginx相关错误信息可去该网址看看: 去看看

    查看错误信息

cat /var/log/nginx/error.log

   3.配置与nginx 与uwsgi的超时时间

   location / {
        # 注意这儿,一般这三个配套修改
        uwsgi_send_timeout 600;        # 指定向uWSGI传送请求的超时时间,完成握手后向uWSGI传送请求的超时时间。
        uwsgi_connect_timeout 600;   # 指定连接到后端uWSGI的超时时间。
        uwsgi_read_timeout 600;        # 指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间。
        uwsgi_pass  127.0.0.1:8000;
        include /home/jason/code/interface/conf/uwsgi_params;       # the uwsgi_params file you installed
    }

   如果是常规http的超时,要设置

   # 注意这儿,一般这三个配套修改
        proxy_send_timeout 600;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;

  例如你使用的是fastcgi, 那么你修改的这个时间应该对应调整为:

  # 注意这儿,一般这三个配套修改
        fastcgi_send_timeout 600;
        fastcgi_connect_timeout 600;
        fastcgi_read_timeout 600;

 

posted @ 2023-05-06 10:40  PKGAME  阅读(200)  评论(0编辑  收藏  举报