Skip to content

Commit 894ae81

Browse files
committed
Add nginx dockerfile and config for a reverse proxy
1 parent f015d14 commit 894ae81

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

docker-compose.yml

+21-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ services:
33
web:
44
build: .
55
env_file:
6-
- .env.dev
6+
- ./.env.prod
77
depends_on:
8-
- db
8+
- db
9+
expose:
10+
- 5000
911
ports:
10-
- 5000:5000
12+
- 5000:5000
1113
volumes:
12-
- .:/web
14+
- .:/web
1315
redis:
1416
image: redis
1517
db:
@@ -19,8 +21,20 @@ services:
1921
POSTGRES_DB: flashlearn
2022
image: postgres:latest
2123
networks:
22-
- default
24+
- default
2325
ports:
24-
- 5405:5432
26+
- 5405:5432
27+
env_file:
28+
- ./.env.prod
2529
volumes:
26-
- ./postgres-data:/var/lib/postgresql/data
30+
- ./postgres-data:/var/lib/postgresql/data
31+
nginx:
32+
build: ./nginx
33+
ports:
34+
- 1337:80
35+
depends_on:
36+
- web
37+
38+
volumes:
39+
postgres-data:
40+
external: true

nginx/Dockerfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM nginx:1.17-alpine
2+
3+
RUN rm /etc/nginx/nginx.conf
4+
COPY ./nginx.conf /etc/nginx/
5+
RUN rm /etc/nginx/conf.d/default.conf
6+
COPY ./nginx.conf /etc/nginx/conf.d/

nginx/nginx.conf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
upstream web {
2+
server web:5000;
3+
server localhost:5000;
4+
server 127.0.0.1:5000;
5+
}
6+
7+
server {
8+
9+
listen 80;
10+
server_name flashlearn_nginx;
11+
12+
location / {
13+
proxy_pass http://web/;
14+
15+
# Do not change this
16+
proxy_set_header Host $host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19+
}
20+
21+
location /static {
22+
rewrite ^/static(.*) /$1 break;
23+
root /static;
24+
}
25+
}

wsgi.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import sys
2+
import logging
13
from flashlearn import create_app
24

5+
logging.basicConfig(stream=sys.stderr)
6+
sys.path.insert(0, "/var/www/")
37
app = create_app()
48

59
if __name__ == "__main__":

0 commit comments

Comments
 (0)