Docker&Nginx&uwsgi部署Django&Vue记录

后端

uwsgi.ini

[uwsgi]
socket=0.0.0.0:6061
# 为所有的socket操作设置内部超时时间(默认4秒)。这个配置会结束那些处于不活动状态超过4秒的连接
socket-timeout=4
listen=2048
processes=4
threads = 2
enable-threads=true
master=true
pidfile=/var/log/jojo/uwsgi.pid
daemonize=/var/log/jojo/uwsgi.log
wsgi-file=/opt/jojo/yingzheng/wsgi.py
pythonpath=/opt/jojo
profiler=true
# enable memory usage report. This will print in the request 1_testid_log information about RSS and address space usage.
memory-report=true
logdate=ture
buffer-size=65535
limit-as=6048
reload-on-as=6048
reload-on-rss=2048

nginx.conf


user root;
worker_processes auto;
pid /run/nginx.pid;

#全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
error_log /var/log/jojo/nginx_error.log;

events {
	worker_connections 2048;
}

http {

	include /etc/nginx/mime.types;
	default_type application/octet-stream;
	access_log /var/log/jojo/nginx_access.log ;

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 30;
	types_hash_max_size 2048;


    proxy_http_version 1.1;
    proxy_set_header Connection "";

    fastcgi_buffer_size 128k;
    fastcgi_buffers 8 128k;
	
	client_max_body_size 1000M;
	client_body_buffer_size 10m;
	client_header_buffer_size 32k;

	##
	# SSL Settings
	##
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;


  server {
      listen       80;
      server_name  localhost;
      charset utf-8;

      proxy_connect_timeout 600;
      proxy_read_timeout 600;
      proxy_send_timeout 600;
      proxy_buffer_size 32k;
      proxy_buffers 4 32k;
      proxy_busy_buffers_size 64k;

      location / {
          include uwsgi_params;
          uwsgi_pass 127.0.0.1:6061;
          uwsgi_connect_timeout 600;
          uwsgi_read_timeout 600;
          uwsgi_send_timeout 600;
      }
      location /NginxStatus {
        stub_status on;
        access_log on;
        auth_basic "NginxStatus";
        # auth_basic_user_file confpasswd;
      }
 }
  server {
      listen       8081;
      server_name  localhost;
      charset utf-8;

      proxy_connect_timeout 600;
      proxy_read_timeout 600;
      proxy_send_timeout 600;
      proxy_buffer_size 32k;
      proxy_buffers 4 32k;
      proxy_busy_buffers_size 64k;

      location /jmeterreport/ {
          root /opt/jojo/static/;
          autoindex on;
          autoindex_exact_size off;
          autoindex_localtime on;
      }
      location /NginxStatus {
        stub_status on;
        access_log on;
        auth_basic "NginxStatus";
        # auth_basic_user_file confpasswd;
      }
  }
}



Dockerfile

FROM jojo-basev2:v1.0.2

RUN mkdir -p /var/log/jojo
RUN mkdir -p /opt/jojo
# 下载代码 & 安装依赖
COPY ./requirements /opt/jojo/requirements
RUN python3 -m pip install --upgrade pip -i http://mirrors.cloud.tencent.com/pypi/simple --trusted-host=mirrors.cloud.tencent.com
RUN pip3 install -r /opt/jojo/requirements/prod.txt -i http://mirrors.cloud.tencent.com/pypi/simple --trusted-host=mirrors.cloud.tencent.com --default-timeout=1000

WORKDIR /opt/jojo
COPY . .
RUN mkdir -p /opt/jojo/logs

# uwsgi配置文件
ADD uwsgi.ini /opt/jojo/uwsgi.ini
## nginx配置文件
ADD nginx.conf /etc/nginx/nginx.conf

docker-compose.yml

version: '3'
services:
  jojo-api:
    hostname: jojo-api
    build:
      context: .
      dockerfile: Dockerfile.api
    image: jojo-api:${VERSION:-latest}
    container_name: jojo-api
    shm_size: 3g
    ports:
      - 6060:80
      - 6066:8081
    environment:
      - PYTHONIOENCODING=utf-8
    volumes:
    - /var/log/jojo:/var/log/jojo
    - /opt/jojo/static:/opt/jojo/static
    command:
      - /bin/sh
      - -c
      - |
        source /etc/profile
        export LC_ALL="en_US.utf8"
        uwsgi /opt/jojo/uwsgi.ini
        nginx -c /etc/nginx/nginx.conf -g "daemon off;"
    privileged: true
    sysctls:
      net.core.somaxconn: 2048

前端

Dockerfile

FROM nginx

RUN rm /etc/nginx/nginx.conf

RUN mkdir /nfs_share
RUN mkdir -p /var/log/nginx

ADD nginx.conf /etc/nginx/nginx.conf

COPY dist/ /usr/share/nginx/html/

nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
# pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
# include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    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;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    # include /etc/nginx/conf.d/*.conf;
    server {
        listen       80;
        server_name  yingzheng;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location / {
          root   /usr/share/nginx/html;
          index  index.html index.htm;
          try_files $uri $uri/ /index.html;
        }

        #location ^~ /apis/ {
        #        proxy_pass http://127.0.0.1:5000/apis/;
        #}

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值