From f72be06618656ff54dedb23a3028baed9cc309a8 Mon Sep 17 00:00:00 2001 From: nineven Date: Sun, 5 Apr 2020 21:02:36 +0800 Subject: [PATCH] add uwsgi start ; add mysql database ;add nginx vhost --- fir_ser/api/views/apps.py | 4 +- fir_ser/fir_ser/settings.py | 15 ++++++- fir_ser/nginx-vhost.conf | 78 +++++++++++++++++++++++++++++++++++++ fir_ser/requirements.txt | 7 +++- fir_ser/uwsgi.conf | 27 +++++++++++++ 5 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 fir_ser/nginx-vhost.conf create mode 100644 fir_ser/uwsgi.conf diff --git a/fir_ser/api/views/apps.py b/fir_ser/api/views/apps.py index 0ba20ce..9b120ea 100644 --- a/fir_ser/api/views/apps.py +++ b/fir_ser/api/views/apps.py @@ -148,8 +148,8 @@ class AppInfoView(APIView): has_combo.update(**{"has_combo": apps_obj.first()}) else: pass - del_cache_response_by_short(apps_obj.short) - del_cache_response_by_short(has_combo.short) + del_cache_response_by_short(apps_obj.first().short) + del_cache_response_by_short(has_combo.first().short) except Exception as e: res.code = 1004 diff --git a/fir_ser/fir_ser/settings.py b/fir_ser/fir_ser/settings.py index 20bc825..28f93dc 100644 --- a/fir_ser/fir_ser/settings.py +++ b/fir_ser/fir_ser/settings.py @@ -78,10 +78,21 @@ WSGI_APPLICATION = 'fir_ser.wsgi.application' # https://docs.djangoproject.com/en/3.0/ref/settings/#databases DATABASES = { + # 'default': { + # 'ENGINE': 'django.db.backends.sqlite3', + # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + # }, 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'flyapp', + 'USER': 'flyuser', + 'PASSWORD': 'flypwd00oo.1', + 'HOST': '127.0.0.1', + 'PORT': '3306', + #设置MySQL的驱动 + 'options': {'init_command': 'SET storage_engine=INNODB'} } + } diff --git a/fir_ser/nginx-vhost.conf b/fir_ser/nginx-vhost.conf new file mode 100644 index 0000000..1dfab50 --- /dev/null +++ b/fir_ser/nginx-vhost.conf @@ -0,0 +1,78 @@ +upstream synchrotron { + least_conn ; + #server 127.0.0.1:8899; + server 127.0.0.1:8898; + #server 127.0.0.1:8897; + #server 127.0.0.1:8896; +} + +proxy_set_header X-Forwarded-For $remote_addr; + +server +{ + listen 80; + listen 443 ssl http2; + server_name fly.dvcloud.xin; + index index.php index.html index.htm default.php default.htm default.html; + root /www/wwwroot/fly.dvcloud.xin; + proxy_connect_timeout 120; + proxy_read_timeout 120; + proxy_send_timeout 120; + #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 + #error_page 404/404.html; + + #HTTP_TO_HTTPS_START + if ($server_port !~ 443){ + rewrite ^(/.*)$ https://$host$1 permanent; + } + #HTTP_TO_HTTPS_END + + ssl_certificate /www/server/panel/vhost/cert/fly.dvcloud.xin/fullchain.pem; + ssl_certificate_key /www/server/panel/vhost/cert/fly.dvcloud.xin/privkey.pem; + ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; + ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; + ssl_prefer_server_ciphers on; + ssl_session_cache shared:SSL:10m; + ssl_session_timeout 10m; + error_page 497 https://$host$request_uri; + + #SSL-END + + + + location ~ ^/(download|api|files) { + proxy_pass http://synchrotron; + } + + location ~ ^/(index|apps|user/login) { + try_files $uri $uri/ /index.html; + } + + location / { + try_files $uri $uri/ /appdownload/index.html; + } + + + #禁止访问的文件或目录 + location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) + { + return 404; + } + + + location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ + { + expires 30d; + error_log off; + access_log /dev/null; + } + + location ~ .*\.(js|css)?$ + { + expires 12h; + error_log off; + access_log /dev/null; + } + access_log /www/wwwlogs/fly.dvcloud.xin.log; + error_log /www/wwwlogs/fly.dvcloud.xin.error.log; +} \ No newline at end of file diff --git a/fir_ser/requirements.txt b/fir_ser/requirements.txt index ace3f1c..7cf738f 100644 --- a/fir_ser/requirements.txt +++ b/fir_ser/requirements.txt @@ -18,6 +18,8 @@ django-qrcode==0.3 django-redis==4.11.0 django-rest-framework==0.1.0 djangorestframework==3.11.0 +dnspython==1.16.0 +drf-extensions==0.6.0 future==0.18.2 idna==2.9 ipython==7.13.0 @@ -27,6 +29,7 @@ jmespath==0.9.5 kiwisolver==1.1.0 lxml==4.5.0 matplotlib==3.2.0 +mysqlclient==1.4.6 networkx==2.4 numpy==1.18.1 oss2==2.9.1 @@ -39,15 +42,17 @@ ptyprocess==0.6.0 pycryptodome==3.9.7 pydot==1.4.1 Pygments==2.5.2 +PyMySQL==0.9.3 pyparsing==2.4.6 python-dateutil==2.8.1 pytz==2019.3 -qiniu==7.2.7 +qiniu==7.2.8 redis==3.4.1 requests==2.23.0 six==1.14.0 sqlparse==0.3.1 traitlets==4.3.3 urllib3==1.25.8 +uWSGI==2.0.18 wcwidth==0.1.8 xmltodict==0.12.0 \ No newline at end of file diff --git a/fir_ser/uwsgi.conf b/fir_ser/uwsgi.conf new file mode 100644 index 0000000..af8c93a --- /dev/null +++ b/fir_ser/uwsgi.conf @@ -0,0 +1,27 @@ +# 对外提供 http 服务的端口 +http = 127.0.0.1:8899 + +#the local unix socket file than commnuincate to Nginx 用于和 nginx 进行数据交互的端口 +socket = 127.0.0.1:8898 + +# the base directory (full path) django 程序的主目录 +chdir = /www/fir_ser + +# Django's wsgi file +wsgi-file = fir_ser/wsgi.py + +# maximum number of worker processes +processes = 8 + +#thread numbers startched in each worker process +threads = 2 + +#monitor uwsgi status 通过该端口可以监控 uwsgi 的负载情况 +stats = 127.0.0.1:9191 + + +# clear environment on exit +vacuum = true + +# 后台运行,并输出日志 +daemonize = /var/log/uwsgi.log