No longer use insecure mode, setup external nginx server (better performances)

This commit is contained in:
Yohann D'ANELLO 2020-06-03 17:51:50 +02:00
parent 3f83fd6ef3
commit a1d02ce657
4 changed files with 37 additions and 3 deletions

View File

@ -7,12 +7,20 @@ WORKDIR /code
# Install LaTeX requirements
RUN apt update && \
apt install -y gettext texlive-latex-extra texlive-fonts-extra texlive-lang-french && \
apt install -y gettext texlive-latex-extra texlive-fonts-extra texlive-lang-french nginx && \
rm -rf /var/lib/apt/lists/*
COPY . /code/
# Configure nginx
RUN ln -s nginx_tfjm.conf /etc/nginx/sites-available/tfjm.conf
RUN rm /var/log/nginx/*.log
RUN ln -s /dev/stdout /var/log/nginx/access.log
RUN ln -s /dev/stderr /var/log/nginx/error.log
RUN rm /etc/nginx/sites-enabled/default
RUN ln -sf /code/nginx_tfjm.conf /etc/nginx/sites-enabled/tfjm.conf
RUN pip install -r requirements.txt
ENTRYPOINT ["/code/entrypoint.sh"]
EXPOSE 8000
EXPOSE 80

View File

@ -4,4 +4,10 @@ python manage.py compilemessages
python manage.py makemigrations
python manage.py migrate
python manage.py runserver 0.0.0.0:8000 --insecure
service nginx start
if [ "$TFJM_STAGE" = "prod" ]; then
gunicorn -b 0.0.0.0:8000 --workers=2 --threads=4 --worker-class=gthread tfjm.wsgi --access-logfile '-';
else
./manage.py runserver 0.0.0.0:8000;
fi

19
nginx_tfjm.conf Normal file
View File

@ -0,0 +1,19 @@
upstream tfjm {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name tfjm;
location / {
proxy_pass http://tfjm;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static {
alias /code/static/;
}
}

View File

@ -9,3 +9,4 @@ django-tables2
djangorestframework
django-rest-polymorphic
psycopg2-binary
gunicorn