Skip to content

Commit

Permalink
Check in a simple docker-compose to run the app behind an nginx proxy
Browse files Browse the repository at this point in the history
So that we can test the reverse proxy configuration fixes in dev

This fixes #24 (comment)

The `docker-compose` (except for `nginx`) should be kept consistent with the
production `docker-compose-prod.yml` with the exception of `DASH_DEBUG_MODE`,
which is set to true so that we can debug errors in the setup more easily

Testing done:
- Built and ran the docker-compose
- Accessing http://localhost:8060/admin gives the same error as
#24 (comment)

```
Uncaught ReferenceError: DashRenderer is not defined
    <anonymous> http://localhost:8060/admin/:58
```
  • Loading branch information
shankari committed Apr 15, 2023
1 parent b7433e8 commit 712cb98
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ To learn more about Dash, please visit [documentation](https://plot.ly/dash).

`docker compose -f docker-compose-dash-app.yml up`

## Test with a reverse proxy

```
docker-compose -f docker-compose-prod-nginx.yml build
docker-compose -f docker-compose-prod-nginx.yml up -d
```

# Dynamic Config

## Set Variables
Expand Down
51 changes: 51 additions & 0 deletions docker-compose-prod-nginx.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# docker-compose-prod-ngnix.yml
# used for testing with the ngnix reverse proxy
version: "3"
services:
dashboard:
build:
context: .
dockerfile: docker/Dockerfile
image: e-mission/opdash:0.0.1
environment:
DASH_DEBUG_MODE: "True"
DASH_SERVER_PORT: 8050
DB_HOST: db
WEB_SERVER_HOST: 0.0.0.0
SERVER_BRANCH: master
CONFIG_PATH: "https://raw.githubusercontent.com/e-mission/nrel-openpath-deploy-configs/main/configs/"
STUDY_NAME: "stage-program"
AUTH_TYPE: "basic" # the other option is cognito
DASH_REQUESTS_PATHNAME_PREFIX: "/"
networks:
- emission
deploy:
restart_policy:
condition: on-failure
depends_on:
- db
- nginxrp
db:
image: mongo:4.4.0
deploy:
replicas: 1
restart_policy:
condition: on-failure
networks:
- emission
nginxrp:
image: nginx:1.24.0
deploy:
replicas: 1
restart_policy:
condition: on-failure
networks:
- emission
volumes:
- ./docker/ngnix.conf:/etc/nginx/nginx.conf:ro
ports:
- "8060:80"


networks:
emission:
46 changes: 46 additions & 0 deletions docker/ngnix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
events { }
http {
server {
listen 80;
charset utf-8;
server_tokens off;

# Re-enable once we have figured out how to get the set_headers module to work
# more_set_headers "X-XSS-Protection: 1; mode=block";
# more_set_headers "Access-Control-Allow-Origin: $host";
# more_set_headers "X-Frame-Options: SAMEORIGIN";
# more_set_headers "Referrer-Policy: same-origin";
# more_set_headers "Allow: GET, POST, HEAD";
if ($request_method ~ ^(OPTIONS)$ ) { return 403; }

# proxy_cookie_path off;
# proxy_cookie_path / "/; HTTPOnly; Secure";

error_page 404 https://www.nrel.gov/notfound;

location /static {
alias /www/static;
}

location / {
rewrite /(.+$) /api/$1 break;
}

location /admin/ {
proxy_pass http://dashboard:8050/;
proxy_pass_header Content-Type;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header Access-Control-Allow-Origin;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_cookie_path / "/; Secure; HttpOnly; SameSite=strict";
client_max_body_size 1G;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
}
}
}

0 comments on commit 712cb98

Please sign in to comment.