-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #135 from LandRegistry/nginx
Use NGINX reverse proxy server
Showing
24 changed files
with
325 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
FROM python:3.12-slim | ||
|
||
RUN useradd containeruser | ||
RUN useradd appuser | ||
|
||
WORKDIR /home/containeruser | ||
|
||
COPY app app | ||
COPY govuk-frontend-flask.py config.py docker-entrypoint.sh requirements.txt ./ | ||
RUN pip install -r requirements.txt \ | ||
&& chmod +x docker-entrypoint.sh \ | ||
&& chown -R containeruser:containeruser ./ | ||
WORKDIR /home/appuser | ||
|
||
# Set environment variables | ||
ENV FLASK_APP=govuk-frontend-flask.py \ | ||
PYTHONDONTWRITEBYTECODE=1 \ | ||
PYTHONUNBUFFERED=1 | ||
|
||
USER containeruser | ||
COPY app app | ||
COPY govuk-frontend-flask.py config.py requirements.txt ./ | ||
RUN pip install -r requirements.txt \ | ||
&& chown -R appuser:appuser ./ | ||
|
||
EXPOSE 9876 | ||
ENTRYPOINT ["./docker-entrypoint.sh"] | ||
USER appuser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,36 @@ | ||
services: | ||
web: | ||
container_name: govuk-frontend-flask | ||
build: . | ||
command: gunicorn --bind 0.0.0.0:5000 -w 4 --access-logfile - --error-logfile - govuk-frontend-flask:app | ||
restart: always | ||
environment: | ||
- CONTACT_EMAIL=[contact email] | ||
- CONTACT_PHONE=[contact phone] | ||
- DEPARTMENT_NAME=[name of department] | ||
- DEPARTMENT_URL=[url of department] | ||
- REDIS_URL=redis://cache:6379 | ||
- REDIS_URL=redis://redis:6379 | ||
- SECRET_KEY=4f378500459bb58fecf903ea3c113069f11f150b33388f56fc89f7edce0e6a84 | ||
- SERVICE_NAME=[name of service] | ||
- SERVICE_PHASE=[phase] | ||
- SERVICE_URL=[url of service] | ||
ports: | ||
- "9876:9876" | ||
volumes: | ||
- .:/home/containeruser | ||
- static_volume:/home/appuser/app/static:rw | ||
expose: | ||
- 5000 | ||
depends_on: | ||
- cache | ||
cache: | ||
container_name: redis | ||
image: redis:7.0-alpine | ||
- redis | ||
redis: | ||
image: redis:7-alpine | ||
restart: always | ||
expose: | ||
- 6379 | ||
nginx: | ||
build: ./nginx | ||
volumes: | ||
- static_volume:/home/appuser/app/static:ro | ||
ports: | ||
- 6379:6379 | ||
|
||
- 443:443 | ||
depends_on: | ||
- web | ||
volumes: | ||
static_volume: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM nginx:stable | ||
|
||
RUN rm /etc/nginx/conf.d/default.conf && \ | ||
mkdir /etc/nginx/ssl && \ | ||
openssl req -x509 -noenc -newkey rsa:2048 -keyout /etc/nginx/ssl/key.pem -out /etc/nginx/ssl/req.pem -days 90 -subj "/C=GB/ST=Devon/L=Plymouth/O=HM Land Registry/OU=Digital/CN=localhost" | ||
|
||
COPY nginx.conf /etc/nginx/conf.d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# generated 2024-09-03, Mozilla Guideline v5.7, nginx 1.26.2, OpenSSL 3.0.13, modern configuration, no OCSP | ||
# https://ssl-config.mozilla.org/#server=nginx&version=1.26.2&config=modern&openssl=3.0.13&ocsp=false&guideline=5.7 | ||
server { | ||
listen 80 default_server; | ||
listen [::]:80 default_server; | ||
|
||
location / { | ||
return 301 https://$host$request_uri; | ||
} | ||
} | ||
|
||
server { | ||
listen 443 ssl; | ||
listen [::]:443 ssl; | ||
http2 on; | ||
|
||
ssl_certificate /etc/nginx/ssl/req.pem; | ||
ssl_certificate_key /etc/nginx/ssl/key.pem; | ||
ssl_session_timeout 1d; | ||
ssl_session_cache shared:MozSSL:10m; # about 40000 sessions | ||
ssl_session_tickets off; | ||
|
||
# modern configuration | ||
ssl_protocols TLSv1.3; | ||
ssl_prefer_server_ciphers off; | ||
|
||
# add security headers | ||
add_header Content-Security-Policy "script-src 'self' 'sha256-GUQ5ad8JK5KmEWmROf3LZd9ge94daqNvd8xy9YS1iDw=' 'sha256-3t81BEe/IfrPieOkVojxAPxOujfIBkzGt+HP2GeblR4='; object-src 'none'; base-uri 'none';" always; | ||
add_header Cross-Origin-Embedder-Policy "require-corp" always; | ||
add_header Cross-Origin-Opener-Policy "same-origin" always; | ||
add_header Cross-Origin-Resource-Policy "same-origin" always; | ||
add_header Permissions-Policy "accelerometer=(), ambient-light-sensor=(), autoplay=(), battery=(), camera=(), cross-origin-isolated=(), display-capture=(), document-domain=(), encrypted-media=(), execution-while-not-rendered=(), execution-while-out-of-viewport=(), fullscreen=(), geolocation=(), gyroscope=(), keyboard-map=(), magnetometer=(), microphone=(), midi=(), navigation-override=(), payment=(), picture-in-picture=(), publickey-credentials-get=(), screen-wake-lock=(), sync-xhr=(), usb=(), web-share=(), xr-spatial-tracking=(), clipboard-read=(), clipboard-write=(), gamepad=(), speaker-selection=(), conversion-measurement=(), focus-without-user-activation=(), hid=(), idle-detection=(), interest-cohort=(), serial=(), sync-script=(), trust-token-redemption=(), unload=(), window-placement=(), vertical-scroll=()" always; | ||
add_header Referrer-Policy "strict-origin-when-cross-origin" always; | ||
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; | ||
add_header X-Content-Type-Options "nosniff" always; | ||
add_header X-Frame-Options "DENY" always; | ||
add_header X-Xss-Protection "1; mode=block" always; | ||
|
||
# enable gzip compression | ||
gzip on; | ||
gzip_comp_level 6; | ||
gzip_proxied any; | ||
gzip_types application/javascript application/json application/xml font/otf font/ttf font/woff font/woff2 image/gif image/jpeg image/png image/svg+xml image/webp text/css text/csv text/javascript text/xml; | ||
|
||
location / { | ||
# forward application requests to the gunicorn server | ||
proxy_pass http://web:5000; | ||
proxy_redirect off; | ||
proxy_set_header Host $host; | ||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; | ||
proxy_set_header X-Real-IP $remote_addr; | ||
} | ||
|
||
location /assets/ { | ||
# serve static files directly, without forwarding to the application | ||
alias /home/appuser/app/static/; | ||
|
||
sendfile on; | ||
tcp_nopush on; | ||
|
||
# set far future expires header | ||
expires 10y; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,9 @@ bandit | |
black | ||
flake8-bugbear | ||
isort | ||
mypy | ||
pep8-naming | ||
pip-audit | ||
pip-tools | ||
pur | ||
pytest-cov | ||
safety |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
python-3.12.2 | ||
python-3.12.5 |