Skip to content

Commit

Permalink
add nignx service
Browse files Browse the repository at this point in the history
  • Loading branch information
vanyakosmos committed Aug 2, 2019
1 parent 3ae6872 commit 6b62301
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 2 deletions.
10 changes: 8 additions & 2 deletions docker-compose.override.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ x-app: &app
- ./backend:/app

services:
db:
nginx:
ports:
- 5432:5432
- 443
volumes:
- ./nginx/dev.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt
- /usr/share/nginx/html

db:
env_file:
- .envs/.local/postgres.env

Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ services:
volumes:
- redisdata:/data

nginx:
build: ./nginx
hostname: nginx
ports:
- 80:80
- 443:443
- 5432:5432
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
- /etc/letsencrypt:/etc/letsencrypt:ro
- /var/www/certbot:/usr/share/nginx/html
depends_on:
- app
- db

app:
<<: *app
command: ["./scripts/run.sh", "prod"]
Expand Down
5 changes: 5 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.17

COPY ./proxy_params /etc/nginx
COPY ./ssl_params /etc/nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
44 changes: 44 additions & 0 deletions nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
server {
listen 80 default_server;
server_name _;
return 444;
}

server {
listen 80;
server_name _;
server_tokens off;

location /.well-known/acme-challenge/ {
root /usr/share/nginx/html;
}

location / {
return 301 https://$host$request_uri;
}
}

server {
listen 443 ssl;
server_name _;
include ssl_params;

client_max_body_size 1M;

location / {
proxy_pass http://app:8000;
}
}


server {
listen 5432;
server_name _;
include ssl_params;

client_max_body_size 1M;

location / {
proxy_pass http://db:5432;
}
}
9 changes: 9 additions & 0 deletions nginx/dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
server {
listen 80 default_server;
server_name _;
client_max_body_size 1M;

location / {
proxy_pass http://app:8000;
}
}
47 changes: 47 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

gzip on;
gzip_comp_level 4;
gzip_min_length 100;
gzip_proxied any;
gzip_types
text/plain text/css text/xml image/svg+xml application/xml
application/xml+rss application/xml+atom text/javascript
application/x-javascript application/javascript application/json;
gzip_disable "msie6";

include /etc/nginx/conf.d/*.conf;
}


stream {
server {
listen 5432;
proxy_pass db:5432;
}
}
4 changes: 4 additions & 0 deletions nginx/proxy_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
4 changes: 4 additions & 0 deletions nginx/ssl_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ssl_certificate /etc/letsencrypt/live/sane.ml/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sane.ml/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

0 comments on commit 6b62301

Please sign in to comment.