Explorar el Código

feat: 增加gunicorn支持

SongZihuan hace 3 años
padre
commit
4613290e74
Se han modificado 2 ficheros con 21 adiciones y 2 borrados
  1. 3 2
      Dockerfile
  2. 18 0
      gunicorn.conf.py

+ 3 - 2
Dockerfile

@@ -3,5 +3,6 @@ WORKDIR /app
 COPY . .
 RUN ["python", "-m", "pip", "install", "--upgrade", "pip"]
 RUN ["python", "-m", "pip", "install", "-r", "requirements.txt"]
-EXPOSE 8080
-ENTRYPOINT ["python", "main.py"]
+RUN ["python", "-m", "pip", "install", "gunicorn"]
+EXPOSE 80
+ENTRYPOINT ["python", "-m", "gunicorn", "-c", "./gunicorn.conf.py", "main:app"]

+ 18 - 0
gunicorn.conf.py

@@ -0,0 +1,18 @@
+# gunicorn.conf.py
+import logging
+import logging.handlers
+from logging.handlers import WatchedFileHandler
+import os
+import multiprocessing
+bind = '0.0.0.0:80'
+timeout = 30      #超时
+
+worker_class = 'gevent'
+workers = multiprocessing.cpu_count() * 2 + 1    #进程数
+threads = 2 #指定每个进程开启的线程数
+
+loglevel = 'info'
+access_log_format = '%(t)s %(p)s %(h)s "%(r)s" %(s)s %(L)s %(b)s %(f)s" "%(a)s"'
+
+accesslog = '/var/log/hblog_acess.log'
+errorlog = '/var/log/hblog_error.log'